vue 支付密码组件

我们要做一个类似京东、支付宝支付时的6位密码组件,效果如下。

专门为PC端写的。移动端的很多框架基本都已经有了,而且实现逻辑会比pc简单,因为是移动端一般配单独键盘,甚至不需要input框,不用考虑鼠标,所以对焦点的处理会简单一些。而且移动端没有password autocomplete 的烦心事。

pc 端如果使用 input password 组件的话(参考文章:https://www.jianshu.com/p/03d2a4744258 ),chrome无论怎样都会弹出密码管理窗口。如使用autocomplete=new-password虽然不会自动填充,但还是会弹出密码管理窗口。所以我们使用input text/tel 组件,然后用•或*给盖住。

Vue 整体代码如下:

:key="i"

v-model="pwdList[i]"

type="tel"

readonly

οnfοcus="this.removeAttribute('readonly');"

maxlength="1"

autocomplete="new-password"

class="u-input"

@input="changeInput"

@click="changePwd"

@keyup="keyUp($event)"

@keydown="oldPwdList = pwdList.length"

>

export default {

props: {

id: {

type: Number,

default: 1 // 当一个页面有多个密码输入框时,用id来区分

}

},

data() {

return {

pwdList: [],

pwdListReal: [],

oldPwdList: [],

isDelete: false,

ipt: ''

}

},

mounted() {

this.ipt = document.querySelectorAll(`#ids_${this.id} .u-input`)

},

methods: {

keyUp(ev) {

let index = this.pwdList.length

if (!index) return

if (ev.keyCode === 8) {

this.isDelete = true

if (this.oldPwdList === this.pwdList.length) {

if (index === this.pwdList.length) {

this.pwdList.pop()

}

index--

} else {

index > 0 && index--

}

this.ipt[index].focus()

} else if (this.isDelete && index === this.pwdList.length && /^\d$/.test(ev.key)) {

this.isDelete = false

this.pwdList.pop()

this.pwdList.push(ev.key)

this.ipt[this.pwdList.length] && this.ipt[this.pwdList.length].focus()

}

this.$emit('get-pwd', this.pwdList.join(''))

},

changePwd() {

let index = this.pwdList.length

index === 6 && index--

this.ipt[index].focus()

},

changeInput() {

let index = this.pwdList.length

const val = this.pwdList[index - 1]

if (!/[0-9]/.test(val)) {

this.pwdList.pop()

return

}

if (!val) {

this.pwdList.pop()

index--

if (index > 0) this.ipt[index - 1].focus()

} else {

if (index < 6) this.ipt[index].focus()

}

}

}

}

.m-password-input {

display: flex;

border-radius: 5px;

padding: 10px 0;

border: 1px solid #cccccc;

position: relative;

margin-left: 1px;

.box-input {

display: inline-block;

position: relative;

border-right: 1px solid #cccccc;

&:last-child{

border-right:0;

}

.u-dot {

position: absolute;

top: 0;

right: 0;

bottom: 0;

left: 0;

display: flex;

align-items: center;

justify-content: center;

font-size: 40px;

}

.u-input {

text-align: center;

font-size: 30px;

float: left;

width: 40px;

height: 20px !important;

color: transparent;

caret-color: #333333;

outline: unset;

border: none;

border-right: 1px solid #cccccc;

&:last-child{

border-right:0;

}

}

}

}

使用:

import PasswordInput from '@/components/PasswordInput'

methods: {

getPwd(password) {

console.log(password)

}

}

参考文章:

支付密码html组件,vue 支付密码组件相关推荐

  1. php支付密码控件,vue支付密码的图文实例

    vue支付密码的图文实例 请输入支付密码 1 2 3 4 5 6 7 8 9 0 删除 export default { props: { payshow: { type: Boolean, defa ...

  2. Vue 单文件组件||Vue 单文件组件的基本用法||webpack 中配置 vue 组件的加载器|| 在 webpack 项目中使用 vue

    Vue 单文件组件 传统组件的问题和解决方案 1. 问题 1. 全局定义的组件必须保证组件的名称不重复 2. 字符串模板缺乏语法高亮,在 HTML 有多行的时候,需要用到丑陋的 \ 3. 不支持 CS ...

  3. vue基础整理-组件

    1--组件 可以理解为页面的一部分,其具有独立的逻辑及功能或界面,同时又能与其他部分进行相应地融合,变成完整的应用.页面可以由这样一个个的组件构成,如导航栏.列表项.弹窗.侧边栏.下拉框.多选框等.页 ...

  4. vue单文件props写法_详解Vue 单文件组件的三种写法

    详解Vue 单文件组件的三种写法 JS构造选项写法 export defaul { data, methods, ...} JS class写法 @Component export default c ...

  5. Vue.js的组件化开发

    组件化开发 什么是组件? web中的组件其实就是页面组成的一部分, 好比是电脑中的每一个元件(如硬盘.键盘.鼠标), 它是一个具有独立的逻辑和功能或界面, 同时又能根据规定的接口规则进行相互融化, 变 ...

  6. Vue入门之组件化开发

    Vue入门之组件化开发 http://www.jianshu.com/p/6718ab1caa81 组件其实就是一个拥有样式.动画.js逻辑.HTML结构的综合块.前端组件化确实让大的前端团队更高效的 ...

  7. 组件、局部的组件、表行组件、组件数据传递

    组件:基础的基础 知识点 组件(Component,Portlet) 组件 组件就是页面上的一小块区域内容,完成一个小的页面功能,请参照视频第六课. 综合例 <div id="myAp ...

  8. 前端Vue自定义支付密码输入键盘Keyboard和支付设置输入框Input

    前端Vue自定义支付密码输入键盘Keyboard和支付设置输入框Input, 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13 ...

  9. MIP 支付组件,支付流程:

    MIP 支付组件,支付流程: 标题 内容 类型 通用 支持布局 responsive,fixed-height,fill,container,fixed 所需脚本 https://c.mipcdn.c ...

最新文章

  1. Head First设计模式之目录
  2. QPainter使用整理
  3. Windows 下安装mysql
  4. c 函数多次声明_【C语言】- static和extern关键字 - 对函数的作用!
  5. utf-8编码的字符串转成unicode(ucs-4)编码的字符串
  6. js实现算法--割字符串
  7. 大话数据结构 : 二叉排序树
  8. 生物数据库建设,等你来~
  9. Linux打开端口iptables
  10. Python 建模步骤
  11. VC Webbrowser操作全解(二)
  12. dell计算机维修教程,戴尔Dell Latitude E6410/E6510官方拆机图解维修手册
  13. 2000元以内办公用计算机,2000元以内买什么笔记本 便宜实用笔记本【推荐】
  14. Photoshop 渐变工具使用
  15. 技术团队如何高效开会
  16. 绘制scara机器人工作空间
  17. java电商平台_Java开源生鲜电商平台
  18. 为什么微信截图无法截取其他软件中的下拉菜单
  19. 实验四 房屋价格预测
  20. 如何做好企业内部培训?

热门文章

  1. 苹果备忘录怎么调字体大小_换手机导致苹果备忘录丢失了怎么恢复?
  2. About 会议讨论
  3. nodejs之express小记
  4. 基于javaweb的二手图书商城平台(java+ssm+jsp+js+jquery+mysql)
  5. 2019斗鱼嘉年华圆满收官:在线观看人次超3.1亿创新高
  6. 【踩坑】objects.githubusercontent下载授权
  7. 常用URL Schema
  8. 亚马逊代运营都包含哪些服务
  9. SQL SERVER数据库修复之REPAIR_ALLOW_DATA_LOSS级别简介和实例
  10. php 删除域名 查询,PHP域名备案查询接口_首发