vue-router go(-1)后退时怎么带参数?

解决方案

  1. 声明一个空的Vue模块eventBus
import Vue from 'vue'

/**
 * 定义空的vue实例,作为 eventbus实现非父子组件之间的通信(vue2.x中去掉了broadcast)
 */
var eventBus = new Vue({});
export default eventBus;
  1. 通过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);
    }
}
  1. 接收参数
import eventBus from '../service/eventbus.js';

//每次激活时
activated(){
    //根据key名获取传递回来的参数,data就是map
    eventBus.$on('choiceHospital', function(data){
        //赋值给首页的附近医院数据模型
        this.nearestOrg = data;
    }.bind(this));
},

版权声明:本文为weixin_45614470原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。