vuejs-challenges icon indicating copy to clipboard operation
vuejs-challenges copied to clipboard

20 - 节流点击指令

Open undefined-zzk opened this issue 1 year ago • 0 comments

// 你的答案

`

  • Implement the custom directive
  • Make sure the onClick method only gets triggered once when clicked many times quickly
  • And you also need to support the debounce delay time option. e.g v-debounce-click:ms

*/

const VDebounceClick = { mounted(el:HTMLButtonElement,binding:DirectiveBinding){ const {arg,value}=binding let timer el.addEventListener('click',()=>{ if(timer) return timer=setTimeout(()=>{ value && value() timer=null },+arg) }) } }

function onClick() { console.log("Only triggered once when clicked many times quickly") }

`

undefined-zzk avatar Feb 04 '24 04:02 undefined-zzk