dvlyadmin_pro/uniapp/utils/stopRepeatClick.js
2025-03-17 18:06:54 +08:00

28 lines
913 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//使用方法示例需要再data中声明noClick:true
//main.js中全局引入
//import stopRepeatClick from './utils/stopRepeatClick.js';
//Vue.prototype.$stopRepeatClick = stopRepeatClick //vue2
//app.config.globalProperties.$stopRepeatClick = stopRepeatClick; //vue3
//引用页使用方式:
//<button class="btn" @click="$stopRepeatClick(btnSave,'')">保存</button>
function stopRepeatClick (methods, info) {
// methods是需要点击后需要执行的函数 info是点击需要传的参数
let that = this;
if (that.noClick) {
// 第一次点击(需要再引用的页面的data中声明noClick:true)
that.noClick= false;
if(info && info !== '') {
// info是执行函数需要传的参数
methods(info);
} else {
methods();
}
setTimeout(()=> {
that.noClick= true;
}, 2000)
} else {
// 这里是重复点击的判断
}
}
export default stopRepeatClick