iT邦幫忙

0

vue 可否監聽所有該頁面的 input ?

  • 分享至 

  • twitterImage

記得之前在 jquery 如果要監聽 input element 的話

$('input, button').on('change'...

就可以一次的監聽全部該頁的 input , button...
只是在 vue 的世界該怎麼進行全部監聽?
我現在的做法是在每個 input 塞 @change...
想問問有沒有更好的做法?

監聽父元素
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

4
通靈亡
iT邦高手 1 級 ‧ 2020-06-24 11:48:26
最佳解答
mounted () {
  // Your Custom Method
  this.someMethod()

  this.$nextTick(()=>{
    document.querySelectorAll('input').forEach(input => {
      input.addEventListener('change', () => {
        console.log('Listening event after you’ve changed some data to wait for the DOM update. ')
      }, false);
    })
  })
}
火爆浪子 iT邦研究生 1 級 ‧ 2020-06-24 12:02:12 檢舉

了解

我要發表回答

立即登入回答