Background: In some places of the applet, if the request is slow, it will open a new page twice, so the user double-clicks in a short time is processed here. If there is a better method, please leave a message. : https://blog.csdn.net/weixin_45581741/article/details/106694815
1. Encapsulate public methods
export function disableDoubleClick(fn, flag, data = {}) {
let that = this;
//这里flag 也是为了防止一个页面多个点击事件
if (that[flag]) {
that[flag] = false;
fn(data);
setTimeout(function() {
that[flag] = true;
}, 1500)
} else {
//如果一直走else分支可能是你没有在页面的data下面挂载flag:true,不然一直都会走else
console.log("请稍后点击")
}
}
2. Hang in vue
import { disableDoubleClick } from '../utils/utilsFn.js'
Vue.prototype.$disableDoubleClick = disableDoubleClick;
- required page usage
<view class="xf-act-btn" @click="$disableDoubleClick (handleLogin ,'onoff')" >开始提货</view>
<view class="history-btn" @click="$disableDoubleClick(historyPage ,'onoff1')">历史提货</view>
注意data定义一下,这里可能我处理的复杂了,可以优化
data(){
return {
onoff:true,
onoff1:true,
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。