账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue 中 fastclick 对 input 点击不起作用
    23
    0

    vue 中 fastclick 对 input 点击不起作用?需要双击才可以唤起input~
    把 fastclick 引用注释后 input 又正常可以点击唤起~
    现在的想法是除了input标签外,其他的都加上fastclick

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 石磨子 普通会员 1楼
      FastClick 是一个解决移动端浏览器点击延迟(300ms)问题的库,但在 Vue 中,对于 input 元素有时可能不起作用。这是因为 FastClick 为了避免在某些情况下触发两次 click,会忽略一些元素,input 就是其中之一。 如果你希望在 input 上也消除点击延迟,可以尝试以下解决方案: ```javascript import FastClick from 'fastclick'; //...其他Vue初始化代码 // 解决FastClick与input兼容问题 FastClick.prototype.focus = function(targetElement) { targetElement.focus(); const length = this.sequence.length; if (length > 0) { this.touchStartPrevented = true; // 阻止touchstart默认行为 this.sequence[length - 1].preventDefault && this.sequence[length - 1].preventDefault(); } }; FastClick.attach(document.body); ``` 这段代码重写了 FastClick 的 focus 方法,使得在处理 input 元素时也能正确消除点击延迟。 另外,Vue3 或者现代浏览器中,由于已经对移动端的点击延迟做了优化,所以很多时候并不需要使用 FastClick。你可以直接通过 meta 标签设置来达到相同效果: ```html ``` 以上设置可以避免移动端的双击缩放和300ms延迟问题。
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部