Uniapp is a cross-platform development framework that is widely used in mobile development. However, many developers will encounter a problem when developing with uniapp: the return page will not refresh.
The specific manifestation of this problem is: when we adjust some data on page A and then return to the previous page B, we find that page B has not been refreshed, and the data is still the original, not the updated one. data. This troubles developers because it may lead to inaccurate page display or confusion for users.
So why does the page return of uniapp not refresh? This is because vue-router is used for routing control in uniapp development, and vue-router adopts stack navigation mode by default. That is to say, switching between different pages is completed by pushing and popping the stack. In this case, when we return from page A to page B, the state of page B is still the previous state and will not be reloaded.
Although this problem seems very difficult, there are actually many solutions.
The routing hook function can perform some operations during the route switching process, such as requesting data in beforeRouteEnter and clearing data in beforeRouteLeave. We can manually refresh the page in beforeRouteEnter when returning to the page, so that the page can be refreshed.
If the application uses vuex for state management, then we can update the status of the page through vuex when returning to the page. In this way, the page status can be updated even if the page does not refresh.
If we adjust the data on page A and need to display these updated data on page B, then we can return For page B, pass these data to page B through the query parameter or params parameter, and then manually call the refresh method of the page to re-render the page.
To summarize, although it is a troublesome problem that the uniapp return page will not refresh, this problem can be solved relatively easily by using routing hook functions, vuex state management or manual re-rendering.
The above is the detailed content of uniapp return page does not refresh. For more information, please follow other related articles on the PHP Chinese website!