1、在一个单独的文件中创建事件总线:创建event-bus.js
import Vue from 'vue';
export const eventBus = new Vue();
2、在传值和接收值的页面都引用js
import { eventBus } from './event-bus'; 路径改成自己的
3、传值页面father.vue中使用 eventBus.$emit
getPagePriceAim({examinationHospitalId:hospitalId}).then((res) => {
this.barCodeList=res.records
eventBus.$emit('dropdownChanged',this.barCodeList)
eventBus.$emit('hospitalId',hospitalId)
})
4、接收页面child.vue使用eventBus.$on
created() {
eventBus.$on('dropdownChanged', this.handleDropdownChanged);
eventBus.$on('hospitalId', this.getHospitalId);
},
handleDropdownChanged(childValue){
this.InspectionPurpose=childValue;
},
getHospitalId(childValue){
this.hospitalId=childValue;
},