Vue实现6位数密码效果

 更新时间:2018年08月18日 16:20:53   作者:Rkatsiteli  
这篇文章主要为大家详细介绍了Vue实现6位数密码,优化iOS WebView卡顿,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

在ios系统,原生 webview 嵌套H5页面使用时,编写完成的6位数输入密码,输入密码卡顿问题的解决方案:

如下图:

原因是因为,CSS 这块 造成的。简单来说,style left 为负数的时候出现的,android 目测不会出现此问题

input[type=tel] {
 opacity: 0;
 z-index: -1;
 position: absolute;
 left:-100%;
}

解决方案:

重新设置 input样式问题

input[type=tel] {
 width: 0.1px;
 height: 0.1px;
 color: transparent;
 position: relative;
 top: 23px;
 background: #000000;
 left: 46px;
 border: none;
 font-size: 18px;
 opacity: 0;
 z-index: -1;
}

全部代码在这,你可以拿出去使用即可

<template>
 <div id="payPwd">
  <header>支付密码设置</header>
  <input ref="pwd" type="tel" maxlength="6" v-model="msg" class="pwd" unselectable="on" />
  <ul class="pwd-wrap" @click="focus">
   <li :class="msg.length == 0?'psd-blink':''"><i v-if="msg.length > 0"></i></li>
   <li :class="msg.length == 1?'psd-blink':''"><i v-if="msg.length > 1"></i></li>
   <li :class="msg.length == 2?'psd-blink':''"><i v-if="msg.length > 2"></i></li>
   <li :class="msg.length == 3?'psd-blink':''"><i v-if="msg.length > 3"></i></li>
   <li :class="msg.length == 4?'psd-blink':''"><i v-if="msg.length > 4"></i></li>
   <li :class="msg.length == 5?'psd-blink':''"><i v-if="msg.length > 5"></i></li>
  </ul>
  <button type="button" @click="sendCode">获取验证码 lodding</button>
 </div>
</template>
<script>
 import api from "./api";
 import "@/js/utils"; //公共方法
 export default {
  components: {},
  data() {
   return {
    msg: '',
   }
  },
  created() {},
  computed: {},
  watch: {
   msg(curVal) {
    if(/[^\d]/g.test(curVal)) {
     this.msg = this.msg.replace(/[^\d]/g, '');
    }
   },
  },
  methods: {
   focus() {
    this.$refs.pwd.focus();
   },
   sendCode() {
    //时间
    utils.sendCode(event.target);

    //showLoading
    utils.view.showLoading();

    setTimeout(function() {
     utils.view.dismissLoading();
    }, 5000);
   }
  },
  mounted() {}
 }
</script>
<style lang="less" scoped>
 #payPwd {
  height: auto;
  header {
   text-align: center;
   height: 80px;
   line-height: 90px;
   text-align: center;
  }
  input[type=tel] {
   width: 0.1px;
   height: 0.1px;
   color: transparent;
   position: relative;
   top: 23px;
   background: #000000;
   left: 46px;
   border: none;
   font-size: 18px;
   opacity: 0;
   z-index: -1;
  }
  //光标
  .psd-blink {
   display: inline-block;
   background: url("./img/blink.gif") no-repeat center;
  }
  .pwd-wrap {
   width: 90%;
   height: 50px;
   padding-bottom: 1px;
   margin: 0 auto;
   background: #fff;
   border: 1px solid #ddd;
   display: flex;
   display: -webkit-box;
   display: -webkit-flex;
   cursor: pointer;
   position: absolute;
   left: 0;
   right: 0;
   top: 13%;
   z-index: 10;
   li {
    list-style-type: none;
    text-align: center;
    line-height: 50px;
    -webkit-box-flex: 1;
    flex: 1;
    -webkit-flex: 1;
    border-right: 1px solid #ddd;
    &:last-child {
     border-right: 0;
    }
    i {
     height: 10px;
     width: 10px;
     border-radius: 50%;
     background: #000;
     display: inline-block;
    }
   }
  }
  button {
   position: relative;
   display: block;
   height: 41px;
   text-align: center;
   margin: 0 auto;
   margin-top: 70%;
   padding: 0 20px;
   border-radius: 5px;
   font-size: 16px;
   border: 1px solid #dddddd;
   background: #dddddd;
   color: #000000;
  }
 }
</style>

附加:如果不想使用光标,直接

//去掉 :class="msg.length == 0?'psd-blink':''" 即可
<li><i v-if="msg.length > 0"></i></li>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • vue实现用户动态权限登录的代码示例

    vue实现用户动态权限登录的代码示例

    这篇文章主要介绍了vue如何实现用户动态权限登录,文中的代码示例介绍的非常详细,对大家学习vue有一定的帮助,需要的朋友可以参考阅读
    2023-05-05
  • Vue+Microapp实现微前端的示例详解

    Vue+Microapp实现微前端的示例详解

    这篇文章主要为大家详细介绍了如何实现以vite+vue3+Microapp为主应用,以vue2+element为子应用的微前端,感兴趣的小伙伴快跟随小编一起学习一下吧
    2023-06-06
  • vue.js路由跳转详解

    vue.js路由跳转详解

    这篇文章主要为大家详细介绍了vue.js路由跳转的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-08-08
  • 解决Vue不能检测数组或对象变动的问题

    解决Vue不能检测数组或对象变动的问题

    下面小编就为大家分享一篇解决Vue不能检测数组或对象变动的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-02-02
  • Vue中使用定时器(setInterval、setTimeout)的两种方式

    Vue中使用定时器(setInterval、setTimeout)的两种方式

    js中定时器有两种,一个是循环执行 setInterval,另一个是定时执行 setTimeout,这篇文章主要介绍了Vue中使用定时器 (setInterval、setTimeout)的两种方式,需要的朋友可以参考下
    2023-03-03
  • Vue打包后访问静态资源路径问题

    Vue打包后访问静态资源路径问题

    在本篇文章里小编给各位整理的是关于Vue打包后访问静态资源路径问题相关知识点,需要的朋友们学习下。
    2019-11-11
  • vue+Vue Router多级侧导航切换路由(页面)的实现代码

    vue+Vue Router多级侧导航切换路由(页面)的实现代码

    这篇文章主要介绍了vue+Vue Router多级侧导航切换路由(页面)的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-12-12
  • Vue 展示.md文件的方法详解

    Vue 展示.md文件的方法详解

    这篇文章主要介绍了Vue 展示.md文件的方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-05-05
  • 基于Vue3+Three.js实现一个3D模型可视化编辑系统

    基于Vue3+Three.js实现一个3D模型可视化编辑系统

    这篇文章主要介绍了基于Vue3+Three.js实现一个3D模型可视化编辑系统,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-09-09
  • Vue3.2 中新出的Expose用法一览

    Vue3.2 中新出的Expose用法一览

    这篇文章主要介绍了Vue3.2 中新出的 Expose 是做啥用的,新的expose方法是非常直观的,而且很容易在我们的组件中实现,本文给大家介绍的非常详细,需要的朋友可以参考下
    2022-07-07

最新评论