Error

[Error][js]클릭이벤트 중복발생 해결

오선지♬ 2024. 3. 13. 19:31
728x90
반응형
let lastClickTime = 0;
const delayThreshold = 300; // Adjust this value based on your requirements (in milliseconds)

this.$el.on('click', '#searchData', (evt) => {
    evt.preventDefault();
    
    const currentTime = Date.now();

    if (currentTime - lastClickTime > delayThreshold) {
        // Perform your button click logic here
        alert("검색");
        
        // Update the last click time
        lastClickTime = currentTime;
    }
});

 

이것을 참고로 moment() 를 사용하여 시간차 계산해서 해결

728x90
반응형