温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

vue如何实现键盘输入支付密码功能

发布时间:2021-04-23 12:43:16 阅读:500 作者:小新 栏目:web开发
Vue开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

小编给大家分享一下vue如何实现键盘输入支付密码功能,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

vue是什么

Vue是一套用于构建用户界面的渐进式JavaScript框架,Vue与其它大型框架的区别是,使用Vue可以自底向上逐层应用,其核心库只关注视图层,方便与第三方库和项目整合,且使用Vue可以采用单文件组件和Vue生态系统支持的库开发复杂的单页应用。

支付密码功能界面如下图:

vue如何实现键盘输入支付密码功能

主要代码如下:

<template>
 <div class="pay-tool">
  <div class="pay-tool-title border-bottom">
   <span class="icon icon-back" @click="backHandle"></span><strong>请输入交易密码</strong>
  </div>
  <div class="pay-tool-content">
   <div class="pay-tool-inputs">
    <div class="item" v-for="i in items"><span class="icon_dot" v-if="password[i]"></span></div>
   </div>
   <div class="pay-tool-link"><router-link class="link" to="/getP">忘记密码?</router-link></div>
  </div>
  <div class="pay-tool-keyboard">
   <ul>
    <li @click="keyUpHandle($event)" v-for="val in keys">
     {{ val }}
    </li>
    <li class="del" @click="delHandle"><span class="icon-del"><</span></li>
   </ul>
  </div>
 </div>
</template>

<script>
 const keys = () => [123456789''0]
 // let sendFlag = true // 防止重复发送密码
 export default {
  data () {
   return {
    items: [012345],
    keyskeys(),
    password: []
   }
  },
  methods: {
   backHandle () {
    this.clearPasswordHandle() // 返回时清除password
    this.$emit('backFnc'// 返回上级
   },
   keyUpHandle (e) {
    let text = e.currentTarget.innerText
    let len = this.password.length
    if (!text || len >= 6return
    this.password.push(text)
    this.ajaxData()
   },
   delHandle () {
    if (this.password.length <= 0return false
    this.password.shift()
   },
   ajaxData () {
    if (this.password.length >= 6) {
     console.log(parseInt(this.password.join(' ').replace(/\s/g'')))
    }
    return false
   },
   clearPasswordHandlefunction () {
    this.password = []
   }
  }
 }
</script>

<style lang="less" scoped>
 .pay-tool {
  position: relative;
  height18.93333333rem;
  background-color#fff;
  overflow: hidden;
  &-title {
   width100%;
   height2.08888888rem;
   padding0 0.8rem;
   line-height2.08888888rem;
   text-align: center;
   overflow: hidden;
   .icon {
    float: left;
    margin-top0.72222222rem;
   }
   strong {
    font-size0.8rem;
   }
  }
  &-content {
   .pay-tool-inputs {
    width14.46666666rem;
    height2.31111111rem;
    margin1.28888888rem auto 0;
    border1px solid #b9b9b9;
    border-radius0.26666666rem;
    box-shadow0 0 1px #e6e6e6;
    display: flex;
    .item {
     width16.66666666%;
     height2.31111111rem;
     border-right1px solid #b9b9b9;
     line-height2.31111111rem;
     text-align: center;
     &:last-child {
      border-right: none;
     }
     .icon_dot {
      display: inline-block;
      width0.51111111rem;
      height0.51111111rem;
      backgroundurl("../../assets/images/icon_dot.png") no-repeat;
      background-size: cover;
     }
    }
   }
   .pay-tool-link {
    padding0.53333333rem 0.8rem 0;
    text-align: right;
    .link {
     font-size0.66666666rem;
     color#3c8cfb;
    }
   }
  }
  .pay-tool-keyboard {
   position: absolute;
   left0;
   bottom0;
   width100%;
   ul {
    width100%;
    display: flex;
    flex-wrap: wrap;
    li {
     width33.3333%;
     height2.25442834rem;
     line-height2.25442834rem;
     text-align: center;
     border-right1px solid #aeaeae;
     border-bottom1px solid #aeaeae;
     font-size0.8rem;
     font-weight: bold;
     &:nth-child(1), &:nth-child(2), &:nth-child(3) {
      border-top1px solid #eee;
     }
     &:nth-child(3), &:nth-child(6), &:nth-child(9), &:nth-child(12) {
      border-right: none;
     }
     &:nth-child(10), &:nth-child(11), &:nth-child(12) {
      border-bottom: none;
     }
     &:nth-child(10), &:nth-child(12), &:active {
      background-color#d1d4dd;
     }
     &:nth-child(12):active {
      background-color#fff;
     }
    }
   }
  }
 }
</style>

注意:页面使用rem布局,根html的font-size为45px。

看完了这篇文章,相信你对“vue如何实现键盘输入支付密码功能”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue
AI

开发者交流群×