如何在vue3里实现长按唤起效果

844 阅读1分钟
长按唤起通常是在H5项目中的一常见效果,但是我们不能使用点击事件,点击事件在点击效果触发的时候就随之触发了。
面对这种情况我们可以给它绑定@goTouchstart@goTouchend两个方法来实现,在@goTouchstart方法里绑定一个定时器,在@goTouchend里清除定时器
例:
   // const timer: any = ref(null)
// const goTouchstart = (index: any) => {
//   timer.value = setTimeout(function () {
//     deteBtn(index);
//   }, 1000);
// }

// const goTouchend = () => {
//   console.log('55');

//   clearTimeout(timer.value);
// }

// const touchEl:any = document.getElementById("touch");
//       var timer;

//       touchEl.ontouchstart = (E) => {
//         timer = setTimeout(function () {
//           onLongPress();
//         }, 3000);
//       };
//       function onLongPress() {
//         alert("长按回调");
//       }
//       touchEl.ontouchend = (E) => {
//         clearTimeout(timer);
//       };
//       console.log(touchEl);