uniapp 绑定/更改手机号,验证码倒计时,手机格式中间四位变成*

在这里插入图片描述

1.判断如果存在手机号则多一个input框为旧手机号栏

<view class="fnListRowBetweenCenter">
	<view class="fnListRowCenter" style="margin: 20rpx 0;">
	<view><text>新手机号码</text></view>
	</view>
	<input class="passwordInput" type="text" value="" v-model="newPhone" @input="phoneModel('newPhone',$event)" placeholder="请输入手机号码" />
</view>
<view class="fnListRowBetweenCenter">
	<view class="fnListRowCenter" style="margin: 20rpx 0;">
	<view><text>验证码</text></view>
	</view>
	<input class="passwordInput" type="text" value="" v-model="code" @input="phoneModel('code',$event)"
	placeholder="请输入验证码" style="width: 28%;"/>
	<view class="code" v-show="sendAuthCode" :disabled="isDisable" @click="getCode">获取验证码</view>
	<view class="code" v-show="!sendAuthCode" :disabled="isDisable">{{ auth_time }}秒后重新获取</view>
</view>
<button class='bottom' @click="submit">立即绑定</button>

2.点击验证码倒计时60s

this.sendAuthCode = false;	//默认true
this.auth_time = 60;	//默认0
var auth_timetimer = setInterval(() => {
	this.auth_time--;
	if (this.auth_time <= 0) {
		this.sendAuthCode = true;
		clearInterval(auth_timetimer);
	}
}, 1000);

3.手机格式中间四位变成*

computed: {
	phone() {
		const reg = /^(\d{3})\d{4}(\d{4})$/
		return this.userInfo.phoneNumber.replace(reg, '$1****$2')
	}
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp中,可以使用uni-simple-router插件来实现手机号验证码验证。具体步骤如下: 1. 安装uni-simple-router插件 ``` npm install uni-simple-router --save ``` 2. 在main.js中引入插件 ```js import Vue from 'vue' import App from './App' import router from './router' import USR from 'uni-simple-router' Vue.config.productionTip = false App.mpType = 'app' const app = new Vue({ ...App, router }) app.$mount() // 使用uni-simple-router插件 Vue.use(USR, { router }) ``` 3. 在需要验证的页面中添加验证码输入框和发送验证码按钮,并绑定相应的事件。 ```html <template> <view> <input type="tel" v-model="phone" placeholder="请输入手机号"/> <input type="tel" v-model="code" placeholder="请输入验证码"/> <button @click="sendCode">发送验证码</button> <button @click="submit">提交</button> </view> </template> <script> export default { data () { return { phone: '', code: '' } }, methods: { sendCode () { // 发送验证码逻辑 }, submit () { // 提交逻辑 } } } </script> ``` 4. 在发送验证码的方法中,通过uni.request发送请求获取验证码,并将验证码存储在本地。 ```js sendCode() { uni.request({ url: 'xxx/sendCode', data: { phone: this.phone }, success: (res) => { // 将验证码存储在本地 uni.setStorageSync('code', res.data.code) } }) } ``` 5. 在提交的方法中,获取用户输入的验证码和本地存储的验证码进行比对,判断验证是否通过。 ```js submit() { const code = uni.getStorageSync('code') if (this.code === code) { // 验证通过 } else { // 验证失败 } } ``` 以上就是在uniapp中实现手机号验证码验证的基本步骤。需要注意的是,发送验证码验证码验证的具体实现需要根据后端接口来进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值