简体   繁体   中英

Vue accessing event listener values between methods

I have the following code below. How can I set the value of "e.detail.name" to "nodeName" and then call it in another method within the same component so I can use the value for an API call.

data() {
  return {
      nodeName: '',
      },
     }
getNodeClicked() {
    window.addEventListener('node_clicked', (e) => { console.log(e.detail.name) })
  },

Isn't it just this (am I missing something?):

data() {
  return {
      nodeName: '',
  },
}
getNodeClicked() {
    window.addEventListener('node_clicked', (e) => this.nodeName = e.detail.name)
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM