<template id="child-template">
  <input v-model="msg">
  <button v-on:click="notify">Dispatch Event</button>
</template>
<!-- 父组件模板 -->
<div id="events-example">
  <p>Messages: {{ messages | json }}</p>
  <child @:child-msg='msg'></child>
</div>
 Vue.component('Child',{
            template:'#child-template',
            data:function(){
                return { msg:'hello'}
            },
            methods:{
                notify: function () {
                  if (this.msg.trim()) {
                    this.$dispatch('child-msg', this.msg)
                    this.msg = ''
                  }
                }
            }

        })
        var partent=new Vue({
            el:"#events-example",
            data:{
                messages:[]
            },
            events:{
                'child-msg':function(msg){
                    this.messages.push(msg)
                }
            }
        })

 

posted on 2017-02-08 14:54  jiawing  阅读(170)  评论(0)    收藏  举报