<div id="app">
<child ref="child"></child>
<button @click="callChildMethod">
callChildMethod
</button>
</div>
<script src="http://cdn.bootcss.com/vue/2.1.10/vue.min.js"></script>
<script type="application/javascript">
Vue.component('child', {
template: '<div></div>',
created: function(){
this.$on('childMethod', function(){
console.log('call child method success!');
});
}
});
new Vue({
el: '#app',
methods: {
callChildMethod() {
console.log('call app method success!');
this.$refs.child.$emit('childMethod');
}
}
})
</script>
网友评论