解决虚拟渲染大数据表格无法使用ctrl+f搜索,自己模拟一个

15 篇文章 0 订阅
11 篇文章 0 订阅
⚠️⚠️⚠️⚠️⚠️⚠️注意。mac、win、上面监听按键是有差异的,比如(e.key === ‘Meta’) || (e.key === ‘Control’),谷歌浏览器和qq浏览器、edge浏览器也有差异e.key === ‘f’ || e.key === ‘F’。,大小写
created() {
    window.addEventListener('keydown', this.keydown)
    window.addEventListener('keyup', this.keyup)
    // 监听双击事件
    window.addEventListener('dblclick', this.doubleClick)
  },


methods: {
	keydown(e) {
      if (ROUTER_PATH.includes(this.$route.path)) {
        if ((e.key === 'Meta') || (e.key === 'Control')) this.CONTROL = 1
        if (e.key === 'f' || e.key === 'F') this.F = 1
        console.log(this.CONTROL, this.F, 'sss')
        if (this.CONTROL === 1 && this.F === 1) {
          this.ctrlf = true
          // this.ctrlf = !this.ctrlf
          // 关闭搜索时 返回表格全部数据
          if (this.ctrlf) {
            this.doubleClick()
            this.searchBill()
          } else {
            this.searchName = ''
          }
          e.preventDefault()
        }
      } else {
        window.removeEventListener('keydown', this.keydown, true)
      }
    },
    keyup(e) {
      if (ROUTER_PATH.includes(this.$route.path)) {
        // mac 和 windows有区别
        const isMac = /macintosh|mac os x/i.test(navigator.userAgent)
        if (isMac) {
          this.CONTROL = 0
          this.F = 0
        } else {
          if (e.key === 'Control') this.CONTROL = 0
          if (e.key === 'f') this.F = 0
        }
      } else {
        window.removeEventListener('keyup', this.keyup, true)
      }
    },
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值