$emit是用来在子组件与父组件通信的语法,将子组件的数据‘发射给’父组件也就是传数据给父组件,具体的语法如下:
子组件传出数据:
this.$emit('tabchange', index)
父组件接收数据:
@tabchange= "tabchange"
并且在tabchange方法里面就可以使用数据:
tabchange(index){
switch(index){
case 0:
this.currenttype = 'pop'
break;
case 1:
this.currenttype = 'new'
break
case 2:
this.currenttype = 'sell'
}
},
最后父组件传数据是props属性,子组件传给父组件则是$emit