uniapp自定义密码输入框

可用于小程序短信验证码输入框、密码数字框…

文章目录

  • uniapp自定义密码输入框
    • 效果图
    • 定义组件
      • template
      • js
      • scss
    • 使用
      • template
      • js

效果图

定义组件

提示: 这里把输入框定义为组件,其他可根据需求调整

template

<template><view><view class="password-input-warp fcc"><view class="password-input_item fcc" :style="{width: width +'rpx', height: height +'rpx', backgroundColor: backgroundColor}"@click="focus = true" v-for="(item, index) in length" :key="index"><view class="num" :class="txtStatus ? 'txtColor' : ''" :style="{fontWeight : bold ? 'bold' : 'normal'}" v-if="password.length > index">{{ showVal ? password[index] : placeholder }}</view><view class="line animation" v-if="password.length == index">|</view></view><input class="input" type="number" :focus="focus" v-model="password" :maxlength="length" @focus="focus = true"@blur="focus=false" @input="passwordInput" /></view></view>
</template>

js

<script>export default {data() {return {focus: false,password: ''}},props: {width: {type: [Number, String],default: 100,},height: {type: [Number, String],default: 100,},backgroundColor: {type: String,default: "#FFF"},bold: { // 是否加粗type: Boolean,default: true},showVal: { // 是否明文type: Boolean,default: false},placeholder: { // 占位type: String,default: "*"},length: { // 密码框长度type: Number,default: 6},txtStatus: {type: Boolean,default: false}},methods: {/*** 监听input事件*/passwordInput(e) {this.$emit('update:value', this.password);if (e.detail.value.length == this.length) {this.focus = falsethis.$emit('confirm')}},/*** 清空内容*/clearInput() {this.password = '';}}}
</script>

scss

<style lang="scss" scoped>.password-input-warp {position: relative;.password-input_item {margin-right: 10rpx;text-align: center;line-height: 100rpx;@include sc(40rpx, $fc3);border-radius: 14rpx;border: 1rpx solid #EFEFEF;box-shadow: 0px 1px 2px 1px rgba(16, 24, 40, 0.05);&:last-child {margin-right: 0;}.num {@include sc(72rpx, $fc6);}.txtColor {color: #F52622;}.line {font-weight: normal;font-size: 40rpx;height: 80rpx;line-height: 76rpx;}.animation {opacity: 0;animation-name: line;animation-timing-function: linear;animation-iteration-count: infinite;animation-duration: .5s;animation-direction: alternate;}@keyframes line {0% {opacity: 1;}100% {opacity: 0;}}}.input {position: absolute;top: 0;left: -100%;height: 100%;opacity: 0;color: transparent;}}
</style>

使用

这里展示使用组件,其他的请忽略

template

<template><view class="container"><button class="comfirmBtn" @click="withdrawTap">申请提现</button><view class="code-popup-wrap"><uni-popup ref="codePopup" type="center"><view class="popup-content tc"><view class="close fcc bold" @click="closeTap"><text class="iconfont iconclose"></text></view><view>手机验证</view><view class="ft24 fc6 pdt10 pdb20">为了您的资产安全,请输入验证码进行安全验证</view><view class="tel bold">{{mobile | mobileFormat}}</view><!-- 使用组件 --><custom-code-input:value.sync="code" showVal:length="4"@confirm="codeInputTap":txtStatus="isCodeColor"ref="code"></custom-code-input><view class="ft22 fc6 tr code" @click="getCodeTap">{{codeTxt}}</view></view></uni-popup></view></view>
</template>

js

<script>import customCodeInput from '../../components/custom-code-input/custom-code-input.vue'export default {data() {return {code: '',codeTxt: '获取验证码',isCodeColor: false,mobile: '18899998888'}},components: {customCodeInput},methods: {openCodeTap() {this.$refs.codePopup.open();},withdrawTap() {// if(!this.isVerify()) {//     return false// };this.$refs.codePopup.open();this.getCodeTap();},/*** 接收子组件传递值*/codeInputTap() {console.log('获取输入内容', this.code);// 执行 申请提现业务},/*** 清除子组件输入框值*/clearInputValTap() {this.$refs.code.clearInput();},closeTap() {this.$refs.codePopup.close();},getCodeTap() {// 发送请求,执行发送验证码的接口、根据需求处理业务}},filters: {mobileFormat(mobile) {if (mobile) {return mobile.substring(0, 3) + '****' + mobile.substring(7)}return '';}}}
</script>

uniapp密码输入框相关推荐

  1. uniapp写一个登录页面

    很高兴为您解答,可以参考以下步骤来写一个登录页面: 创建一个uniapp项目,并在项目中创建一个登录页面: 在登录页面中添加用户名和密码输入框,以及一个登录按钮: 在登录按钮的点击事件中,添加验证用户 ...

  2. uniapp登录页设计

    uniapp的登录页设计思路,设计一个用户名输入框,一个密码输入框,一个提交按钮,使用form表单提交.提交后,后台验证用户名和密码,如果正确就返回特定值,uniapp根据结果跳转到另一页面,不正确返 ...

  3. uniapp ios证书申请和上架全流程

    目前市场上流行着很多多端开发框架,就拿uniapp和react native来比较,uniapp比react native方便很多,react的编译还需要mac电脑,而uniapp则轻量得多,一台wi ...

  4. 5.3.2 表单内数据的获取 -表单的使用- 常用语法【uni-app教程uniapp教程(黄菊华-跨平台开发系列教程)】

    5.3.2 表单内数据的获取 在表单的组件,我们需要定义name的值,然后我们在提交表单的时候,就可以通过name获取对应的值,获取内容的格式如下: e.detail.value.组件的name 提示 ...

  5. vue 和 uniapp 的密码框小眼睛(通用)

    密码输入框的小眼睛适合Vue 或者 uniapp使用 步骤1动态绑定:type 步骤2在data里声明 Data(){ Return{ seen:'', pwdType: 'password', // ...

  6. 文本输入框、密码输入框

    当用户要在表单中键入字母.数字等内容时,就会用到文本输入框.文本框也可以转化为密码输入框. 语法: <form><input type="text/password&quo ...

  7. uniapp 鸿蒙,关于前端:uniapp项目安装运行操作手册

    一,装置运行环境 1.下载node.js node.js下载链接node.js 请下载长期反对版. 2.装置node.js 装置教程百度可查这里就不具体阐明了,装置教程地址链接 3.验证node是否装 ...

  8. uniapp 中如何使用echart_uniapp中如何引用echarts

    uniapp引用echarts的方法:1.通过uni-app官网直接安装echarts插件生成echarts项目模板:2.创建一个新的hello uni-app项目模板:3.把echarts放到com ...

  9. uniapp移动端H5在线预览PDF等文件实现源码及注解

    uniapp移动端H5预览文件实现分为两个场景处理: (这里以预览PDF文件为示例,在线预览就是查看网络文件) 1. IOS客户端预览PDF文件 IOS客户端预览PDF文件可以通过跳转文件地址实现预览 ...

  10. uniapp兼容H5和小程序订阅消息授权开发封装,使用方便

    本文使用 uniapp 框架开发,因为H5的订阅消息和小程序的订阅消息的授权流程不一样,但是很多地方需要使用授权,所以我封装了一个兼容H5和小程序订阅消息授权的方法,使用比较方便,希望能够帮助到你,实 ...

最新文章

  1. [Java]LeetCode297. 二叉树的序列化与反序列化 | Serialize and Deserialize Binary Tree
  2. 基于Service Mesh构建更现代的服务架构
  3. music算法原理_大话FMCW雷达之区域检测原理
  4. openCV实战(一):rectangle函数使用
  5. php实战 案例教程,php实战案例
  6. ASP.NET MVC中,通用的异常处理
  7. 一致性Hash简单介绍和使用
  8. 2012二级java真题_2012年计算机二级JAVA模拟试题及答案详解汇总
  9. rust笔记4 slice类型
  10. 单线程+异步协程的简单爬虫模型
  11. 【读书笔记】-《软件测试的艺术》
  12. 泛联新安EDA系列——国内自主研发,首款集成双国军标的HDL代码缺陷管理平台VHawk
  13. flink 窗口表值函数
  14. 教你AI智能合并生成多个新视频,并去声添加新音乐
  15. matlab安装mosek工具包
  16. 密码找回逻辑漏洞总结
  17. Uri Herrera 近日宣布 Nitrux 2.1 的发布和普遍可用性
  18. 如果你是iPhone用户,要学会这样清理手机垃圾,减缓卡顿小妙招
  19. FTP服务器的两种工作模式
  20. 喜讯 | 创新引领,数据赋能,数说故事再度斩获金鼠标数字营销大赛双项大奖

热门文章

  1. mysql星期几转为英文_MySQL如何获取一个指定日期所对应的的星期几(英文星期信息-dayname函数)呢?...
  2. Windows环境下32位汇编语言程序设计(典藏版) 高清完整
  3. 关于滚动贯穿的解决方案
  4. Android锁屏Demo
  5. BYD Mes系统接入示例图源码
  6. 土木工程计算机设计考试科目一模拟试题,科目一电脑模拟考试,原来这么简单,看完这个科一不用愁!...
  7. jsencrypt 公私钥解加密
  8. java.lang.IllegalArgumentException: Receiver not registered
  9. 相对定位(relative)和绝对定位(absolute)的区别
  10. vue run dev报错 缺少package.json文件