代码之家  ›  专栏  ›  技术社区  ›  Philipp Mochine

Vue直接从侦听事件接收数据[我可以创建内联处理程序吗?]

  •  0
  • Philipp Mochine  · 技术社区  · 8 年前

    有没有一种方法可以不创建函数或$on直接接收值? 诸如此类:

    <my-custom-component @saved="data => variable = data"></my-custom-component>
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   bbsimonbb    8 年前

    That works. 有什么问题吗?

    密码

    Vue.component('my-custom-component',{
      template : `<button @click='$emit("saved",{data : "hello cobber"})'>Click me !</button>`
    })
    
    vm = new Vue({
      el : '#vueRoot',
      data : { variable : null }
    })
    

    加成

    <div id="vueRoot">
      <my-custom-component @saved="data => variable = data"></my-custom-component>{{variable}}
    </div>
    
    推荐文章