ShortPassword 短密码组件

介绍

短密码输入框,可用于输入密码、短信验证码等

安装

  1. import { createApp } from 'vue';
  2. import { ShortPassword } from '@nutui/nutui';
  3. const app = createApp();
  4. app.use(ShortPassword);

代码示例

公用片段

  1. <nut-shortpassword
  2. v-model="state.value"
  3. v-model:visible="state.visible"
  4. :no-button="state.noButton"
  5. :length="state.length"
  6. :error-msg="state.errorMsg"
  7. @change="methods.onChange"
  8. @complete="methods.onComplete"
  9. @ok="methods.onOk"
  10. @tips="methods.onTips">
  11. </nut-shortpassword>
  1. import { reactive, getCurrentInstance } from 'vue';
  2. setup() {
  3. let { proxy } = getCurrentInstance();
  4. const state = reactive({
  5. visible: false,
  6. noButton: true,
  7. value: '',
  8. errorMsg: '',
  9. length: 6
  10. });
  11. const methods = {
  12. onChange(val: string) {
  13. val && proxy.$toast.text(val);
  14. },
  15. onOk(val: string) {
  16. val && proxy.$toast.text(val);
  17. state.visible = false;
  18. },
  19. onComplete() {
  20. },
  21. onTips() {
  22. proxy.$toast.text('执行忘记密码逻辑');
  23. }
  24. };
  25. return {
  26. state,
  27. methods
  28. };
  29. }

基础用法

  1. <nut-cell title="基础用法" is-link @click="state.visible = true;"></nut-cell>

显示按钮组

  1. <nut-cell title="显示按钮组" is-link @click="state.visible = true;state.noButton = false;"></nut-cell>

自定义密码长度4

  1. <nut-cell title="自定义密码长度4" is-link @click="state.visible = true;state.length = 4;"></nut-cell>

忘记密码提示语事件回调

  1. <nut-cell title="忘记密码提示语事件回调" is-link @click="state.visible = true;"></nut-cell>

错误提示语

  1. <nut-cell title="错误提示语" is-link @click="state.visible = true;state.errorMsg = '请输入正确密码';"></nut-cell>

Prop

字段说明类型默认值
v-model密码初始值String
v-model:visible是否展示短密码框Booleanfalse
title标题String请输入密码
desc密码框描述String您使用了虚拟资产,请进行验证
tips提示语String忘记密码
close-on-click-overlay是否点击遮罩关闭Booleantrue
no-button是否隐藏底部按钮Booleantrue
length密码长度,取值为4~6String、Number6
error-msg错误信息提示String‘’

Event

事件名称说明回调参数
change输入密码时触发事件value
ok点击确实时触发事件value
cancel点击取消时触发事件value
close点击关闭图标时触发事件value
complete输入完成的回调value

ShortPassword  短密码 - 图1