1.html部分
<div id="test">
<my-component @click.native="father"></my-component>
</div>
2.自定义组件调用父级函数
这是其中的一种方法
Vue.component('my-component',{
templata:`<button @click="father"></button>`,
});
另一种方法
Vue.component('my-component',{
templata:`<button @click="isChild"></button>`,
methods:{
isChild:function(){
this.$emit('father');//不带参数
this.$emit('father',参数写在这);//带参数
}
}
});
3.new一个Vue
myVue=new Vue({
el:'#test',
methods:{
father:function(){
alert('我是父级')
}
}
})