注:
1.滑动或多次点击时警告[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.
一、解决方法一
在touch的事件监听方法上绑定第三个参数{ passive: false },
通过传递 passive 为 false 来明确告诉浏览器:事件处理程序调用 preventDefault 来阻止默认滑动行为。
element.addEventListener('touchstart',function () {},{ passive: false });
二、解决方法二
// 使用全局样式样式去掉 * { touch-action: pan-y; }
三、https://chat.openai.com/
<button @click.prevent="onClick">Click me</button>...methods: {onClick(event) {event.preventDefault();// Do something else}},...mounted() {this.$refs.button.addEventListener('click', this.onClick, { passive: false });},...beforeUnmount() {this.$refs.button.removeEventListener('click', this.onClick, { passive: false });}