fastclick:解决移动端点击事件300ms延迟

757 阅读1分钟

一、使用npm安装:

npm install fastclick -S

二、main.js中引入

import FastClick from 'fastclick'
//初始化FastClick实例。在页面的DOM文档加载完成后
FastClick.attach(document.body)


三.使用过程中存在的bug:

当使用FastClick 时,input框在ios上点击输入调取手机自带输入键盘不灵敏,有时候甚至点不出来。而安卓上完全没问题。这个原因是因为FastClick的点击穿透。解决方法:

mounted(){
	FastClick.prototype.onTouchEnd = function(event) {
		if(event.target.hasAttribute("type") && event.target.getAttribute("type") == "text") {
			event.preventDefault();
			return false;  			
		}		
	}
}