Vue returns to the previous page automatic refresh method

In vue, when returning to the previous page: if the page is open, the page will not be automatically refreshed, and the state of the last jump will not be updated;

Reason: The switch of vue-router is different from the traditional page switch, but the switch between routes, which is actually the switch between components. When referencing the same component, it will directly call the cache instead of calling created(), mounted( ) function .

Solution

1. Return to refresh page

Add the following code to the return page

watch:{

    '$route' () {

      this.getList(); //My initialization method

    }

  }

Monitor the router, and execute the initialization interface method when the router changes.

Here is my workaround.

2. Return to the previous page: If the page is not opened, it will be opened automatically; if the page is already opened, the page will not be refreshed

        goBack() {

            const obj = {

                path: "/product/base",

                query: {

                       //Need to pass parameters

                    t: Date.now(),

                    pageNum: this.$route.query.pageNum

                }

            };

            this.$tab.closeOpenPage(obj);

            this.reset();

        }

Guess you like

Origin blog.csdn.net/zw899004/article/details/130270695