The problem has been solved! (It is not a rollback operation, so parameters cannot be taken. If necessary, refer to this method)
Business needs
I am currently working on an Internet product for elderly care services. On multiple pages, you can enter the "Hospital List" page, select the hospital you want to serve, and then go back. For example, both "Home" and "Appointment" can enter the "Hospital" page.
This means "hospital list page". You don't know or need to know which page the last page you visited was. You just need to select the hospital and return. Of course, you can also tell the hospital list page what the name of the previous page is by passing parameters, and then go back. But if there are too many pages, imagine how many judgment codes there will be on the hospital list page?
Solution
1. Declare an empty Vue moduleeventBus
import Vue from 'vue'
/**
* 定义空的vue实例,作为 eventbus实现非父子组件之间的通信(vue2.x中去掉了broadcast)
*/
var eventBus = new Vue({});
export default eventBus;
2. "Hospital List Page" passes eventBus.$emit to the previous page
Official website grouter.go(-1) // Go back one step to record, which is equivalent to history.back(). It cannot take parameters. 2 solutions: 1. Jump to the previous page by routing instead of returning 2. Data sharing can be achieved through store or vuex.
The problem has been solved! (It is not a rollback operation, so parameters cannot be taken. If necessary, refer to this method)
Business needs
I am currently working on an Internet product for elderly care services. On multiple pages, you can enter the "Hospital List" page, select the hospital you want to serve, and then go back. For example, both "Home" and "Appointment" can enter the "Hospital" page.
Solution
1. Declare an empty Vue module
eventBus
2. "Hospital List Page" passes
eventBus.$emit
to the previous page3. "Home" and "Reservation" pages receive parameters
Reference
How to communicate between vue non-parent-child components
This goes against the meaning of historical records. If it is accessed with parameters, it should be forward.
In addition, SPA does not have the problem of data transmission. Why does backing off need to have parameters?
Official website grouter.go(-1) // Go back one step to record, which is equivalent to history.back(). It cannot take parameters.
2 solutions: 1. Jump to the previous page by routing instead of returning 2. Data sharing can be achieved through store or vuex.
Don’t you use this.$router.back() to go back by yourself? Do you need to determine where it comes from?