注:
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 });
二、解决方法二文章来源:https://www.toymoban.com/news/detail-557414.html
// 使用全局样式样式去掉
* { touch-action: pan-y; }
三、https://chat.openai.com/文章来源地址https://www.toymoban.com/news/detail-557414.html
<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 });
}
到了这里,关于解决警告:Unable to preventDefault inside passive event listener due to target being treated as passive.的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!