解决方案
- 声明一个空的Vue模块eventBus
import Vue from 'vue'
var eventBus = new Vue({});
export default eventBus;
- 通过eventBus.$emit传参给上一个页面
import eventBus from '../service/eventbus.js';
methods:{
//列表选中具体医院的点击事件
goback(hospital){
//传递一个map,choiceHospital是key,hospital是value
eventBus.$emit('choiceHospital',hospital);
//调用router回退页面
this.$router.go(-1);
}
}
- 接收参数
import eventBus from '../service/eventbus.js';
//每次激活时
activated(){
//根据key名获取传递回来的参数,data就是map
eventBus.$on('choiceHospital', function(data){
//赋值给首页的附近医院数据模型
this.nearestOrg = data;
}.bind(this));
},