picture,
1. Create a new common file in the root directory and create a common.js file, enter the following code
// 防止处理多次点击
function noMultipleClicks(methods, info) {
// methods是需要点击后需要执行的函数, info是点击需要传的参数
let that = this;
if (that.noClick) {
// 第一次点击
that.noClick= false;
if(info && info !== '') {
// info是执行函数需要传的参数
methods(info);
} else {
methods();
}
setTimeout(()=> {
that.noClick= true;
}, 2000)
} else {
// 这里是重复点击的判断
console.log("请稍后点击")
}
}
//导出
export default {
noMultipleClicks,//禁止多次点击
}
2. Introduction of man.js file
//配置公共方法
import common from './common/common.js'
Vue.prototype.$noMultipleClicks = common.noMultipleClicks;
3. Quote in the actual page, without parameters, just pass a method directly.
//记得在data中挂载 noClick:true
data() {
return {
noClick:true,
}
},
<view class="bottom-btn-box">
<view class="submit-btn" @click="$noMultipleClicks(commitWork)">提交</view>
</view>
methods:{
commitWork(){
//balabala
}
}
4. Quote in the actual page, with parameters, just pass a method and a parameter.
//记得在data中挂载 noClick:true
data() {
return {
noClick:true,
}
},
<view class="bottom-btn-box">
<view class="pay" @click.stop="$noMultipleClicks(goPay, item)" >支付</view>
</view>
methods:{
goPay(item){
//balabala
}
}
5.Reference Taibin
Dabin
Dabin
Dabin
5. Finally
If you think the article is good, remember to give it a thumbs up, follow it, and add it to your favorites. Please correct me if there are any mistakes. If you need to reprint it, please indicate the source. Thank you! ! !