Vue 中方法节流
export const throttle = (fn,delay) => {
let prev = 0;
console.log('prev:',prev)
return function () {
let now = new Date().getTime();
let context = this;
let args = Array.prototype.slice.call(arguments)
console.log('now:',now,'prev:',prev)
if(now - prev >=delay){
fn.apply(context, args)
prev = now
}
}
}
<i style="margin-left: 5px;" @click="copy(scope.row.notify_url)" title="复制"></i>
....
import { throttle } from '@/utils/tool'
....
methods:{
copy: throttle(function (val) {
let oInput = document.createElement('input');
oInput.value = val;
document.body.appendChild(oInput);
oInput.select();
console.log(oInput.value)
document.execCommand("Copy");
this.$message({
message: '已成功复制到剪切板',
type: 'success'
});
oInput.remove()
}, 5000)
}