this.$emit用法

6,870 阅读1分钟

主要用法:子组件向父组件传值

现在有一个父组件 scheduling.vue,父组件中引用了子组件schedulingAdd.vue。
父组件代码:

<SchedulingAdd @close-view="returnList"></SchedulingAdd>

子组件代码:

quit() {
    this.$emit("close-view","add");
}

当在子组件中用到quit()方法的时候;父组件就会执行returnList方法;同时把add传给这个方法。

returnList(val) {
     this.currView = val
}

这里的this.currView就获得了子组件传来的值,即:add。