为了账号安全,请及时绑定邮箱和手机立即绑定

vue.js自定义事件如何触发的?

vue.js自定义事件如何触发的?

慕虎7371278 2018-08-02 10:09:27
<script type="x/template" id="child-template">  <input v-model="msg">  <button v-on:click="notify">Dispatch Event</button></script><div id="events-example" class="demo">  <p>Messages: {{ messages | json }}</p>  <child v-on:child-msg="handleIt"></child></div><script>    Vue.component('child', {      template: '#child-template',      data: function () {        return { msg: 'hello' }      },      methods: {        notify: function () {          if (this.msg.trim()) {            this.$dispatch('handleIt', this.msg);            this.msg = ''          }        }      }    })    var parent = new Vue({      el: '#events-example',      data: {        messages: []      },      events: {        'handleIt': function (msg) {          this.messages.push(msg)        }      }    })</script>如上代码中,自定义的child-msg事件是如何触发的并最终执行了handleIt函数?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 2273 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信