最近在做vue–H5项目时,需要实现当用户输入内容时,防止因为用户点触摸某处导致页面闪烁。(因为ios端,input框聚焦时,键盘遮挡了input框,所以我在聚焦时给整体加了padding,如果用户不小心触摸了这个padding,整个页面就跟触电一样抖一哈~~奇奇怪怪的现象。。。)言归正传,所以我就想着,加个监听吧,结果…
刚开始时,我是这样写的
// 添加监听
this.$refs.spyj.addEventListener("touchstart", (e) => { e.preventDefault && e.preventDefault(); e.returnValue=false; e.stopPropagation && e.stopPropagation(); return false; })// 移除监听
this.$refs.spyj.removeEventListener("touchstart", (e) => { return true; })失败了。。。(蓦然回首,我怕不是个傻子吧? ) 后来,我去找了度娘,嗯,原来如此
// 添加监听 this.$refs.spyj.addEventListener("touchstart", this.zuzhi) // 操作 zuzhi() {} // 移除监听 this.$refs.spyj.removeEventListener("touchstart", this.zuzhi)