問題已經解決了! (并非回退操作就不能帶參數,如有需要的參考此類做法)
業務需求
這意味著“醫院列表頁”,并不知道也不需要知道,訪問的上一個頁面是哪個頁面,只需要選擇完醫院之后返回就可以了。
當然也可以通過傳參來告訴醫院列表頁,上一個頁面的name是什么,然后再回退回去。但如果頁面多了,想象一下醫院列表頁的判斷代碼會有多少?



解決方案
1. 聲明一個空的Vue模塊eventBus
import Vue from 'vue'/**
* 定義空的vue實例,作為 eventbus實現非父子組件之間的通信(vue2.x中去掉了broadcast)
*/var eventBus = new Vue({});export default eventBus;
2. “醫院列表頁”通過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);
}
}
3. “首頁”以及“預約”頁面接收參數
import eventBus from '../service/eventbus.js';//每次激活時activated(){ //根據key名獲取傳遞回來的參數,data就是map
eventBus.$on('choiceHospital', function(data){ //賦值給首頁的附近醫院數據模型
this.nearestOrg = data;
}.bind(this));
},
參考