uni app 记忆笔记
1.防止重复点击
1、在根目录下新建一个js 文件,输入下面代码
function noMultipleClicks(methods) {
let that = this;
if (that.noClick) {
that.noClick= false;
methods();
setTimeout(function () {
that.noClick= true;
}, 12000)
} else {
uni.showToast({
title: "请两分钟后重试",
icon: "none",
duration: 2000
})
}
};
//导出
export default noMultipleClicks; //禁止多次点击
2、在man.js里把文件引入
3、在实际页面中引用,不带参数,直接传一个方法就行
// 记得在data中挂载 noClick:true
data() {
return {
noClick:true, //防止重复点击
}
},
<button @click="$noMultipleClicks(createGoodOrder)">
立即兑换
methods:{
createGoodOrder(){
//开始你的表演
}
}
2.随机生成数字
/**
生成3位
**/
getSortCode:function() {
let code=’’;
for (var i = 0; i < 3; i++) {
//获取0-9的随机整数
let randomNum=parseInt(Math.floor(Math.random()*10));
//把随机整数拼接成字符串(验证码)
code+=randomNum+’’;
}
console.log(code)
},
3.返回上一页并携带参数或者执行上一页的制定操作
var pages = getCurrentPages();
var prevPage = pages[pages.length - 2];
var object = {
address1: this.provinceName,
address2: this.cityName,
address3: this.townName,
addressDetail: this.adress,
name: this.name,
phone: this.phone
}
prevPage.
v
m
.
o
t
h
e
r
F
u
n
(
o
b
j
e
c
t
)
;
/
/
重
点
vm.otherFun(object); //重点
vm.otherFun(object);//重点vm
setTimeout(() => {
uni.navigateBack({
success:function() {
prevPage.$vm.getAddressList();
}
});
}, 1000)
4.判断是否是有效手机号
if (phone !== ‘’) {
var reg = /^1[3456789]\d{9}$/;
if (!reg.test(phone)) {
let that = this
that.phone = ‘’
uni.showModal({
title: ‘错误’,
content: ‘请输入有效的手机号码’,
showCancel: false
});
}
}
5.金额是否有效
// 金额校验
check(e) {
//正则表达试
e.target.value = (e.target.value.match(/^\d*(.?\d{0,2})/g)[0]) || null
//重新赋值给input
this.$nextTick(() => {
this.money = e.target.value
})
uni.hideKeyboard(); //打开数字键盘
},