简体   繁体   English

Vue 在方法之间访问事件监听器值

[英]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.如何将“e.detail.name”的值设置为“nodeName”,然后在同一组件中的另一个方法中调用它,以便可以将该值用于 API 调用。

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)
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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