1.0.1 • Published 3 years ago

@ophiuchus/password-input v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

PasswordInput 密码输入框

介绍

带网格的输入框组件,可以用于输入密码、短信验证码等场景,通常与数字键盘组件配合使用。

引入

import Vue from 'vue';
import PasswordInput from '@ophiuchus/password-input';
import NumberKeyboard from '@ophiuchus/number-keyboard';

Vue.use(PasswordInput);
Vue.use(NumberKeyboard);

代码演示

基础用法

搭配数字键盘组件来实现密码输入功能。

<!-- 密码输入框 -->
<sf-password-input
  :value="value"
  :focused="showKeyboard"
  @focus="showKeyboard = true"
/>
<!-- 数字键盘 -->
<sf-number-keyboard
  v-model="value"
  :show="showKeyboard"
  @blur="showKeyboard = false"
/>
export default {
  data() {
    return {
      value: '123',
      showKeyboard: true,
    };
  },
};

自定义长度

通过 length 属性来设置密码长度。

<sf-password-input
  :value="value"
  :length="4"
  :focused="showKeyboard"
  @focus="showKeyboard = true"
/>

格子间距

通过 gutter 属性来设置格子之间的间距。

<sf-password-input
  :value="value"
  :gutter="10"
  :focused="showKeyboard"
  @focus="showKeyboard = true"
/>

明文展示

mask 设置为 false 可以明文展示输入的内容,适用于短信验证码等场景。

<sf-password-input
  :value="value"
  :mask="false"
  :focused="showKeyboard"
  @focus="showKeyboard = true"
/>

提示信息

通过 info 属性设置提示信息,通过 error-info 属性设置错误提示,例如当输入六位时提示密码错误。

<sf-password-input
  :value="value"
  info="密码为 6 位数字"
  :error-info="errorInfo"
  :focused="showKeyboard"
  @focus="showKeyboard = true"
/>
<sf-number-keyboard
  v-model="value"
  :show="showKeyboard"
  @blur="showKeyboard = false"
/>
export default {
  data() {
    return {
      value: '123',
      errorInfo: '',
      showKeyboard: true,
    };
  },
  watch: {
    value(value) {
      if (value.length === 6 && value !== '123456') {
        this.errorInfo = '密码错误';
      } else {
        this.errorInfo = '';
      }
    },
  },
};

API

Props

参数说明类型默认值
value密码值string''
info输入框下方文字提示string-
error-info输入框下方错误提示string-
length密码最大长度number | string6
gutter输入框格子之间的间距,如 20px 2em,默认单位为pxnumber | string0
mask是否隐藏密码内容booleantrue
focused是否已聚焦,聚焦时会显示光标booleanfalse

Events

事件名说明回调参数
focus输入框聚焦时触发-

样式变量

组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制

名称默认值描述
@password-input-height50px-
@password-input-margin0 @padding-md-
@password-input-font-size20px-
@password-input-border-radius6px-
@password-input-background-color@white-
@password-input-info-color@gray-6-
@password-input-info-font-size@font-size-md-
@password-input-error-info-color@red-
@password-input-dot-size10px-
@password-input-dot-color@black-