在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue 如何實(shí)現(xiàn)“長(zhǎng)按”與“普通點(diǎn)擊”并存且互不影響?

vue 如何實(shí)現(xiàn)“長(zhǎng)按”與“普通點(diǎn)擊”并存且互不影響?

使用場(chǎng)景:

在一個(gè) vue 項(xiàng)目中,有一個(gè)按鈕。

遇到的問題:

點(diǎn)擊一下輸出了:111。(沒問題)
長(zhǎng)按輸出了:111,222.

想要實(shí)現(xiàn):

點(diǎn)擊一下輸出:111。
長(zhǎng)按只輸出:222.

如何實(shí)現(xiàn)呢?

<a class="btn btn-primary"
    @touchstart="handleClick"
    @touchend="clearLoop">button</a>
methods: {
    handleClick () {
      clearInterval(this.Loop)
      this.Loop = setTimeout(() => {
        console.log('222')
      }, 1000)
      console.log('111')
    },
    clearLoop () {
      clearInterval(this.Loop)
    }
  }
回答
編輯回答
忘了我

可以用時(shí)間戳來比較
touchstart的時(shí)候記錄下來, touchend的時(shí)候與當(dāng)前時(shí)間比較
超過一定時(shí)間的視為長(zhǎng)按, 沒超過的視為點(diǎn)擊

2018年7月13日 11:16