When we are writing projects, we often encounter situations where the user performs an action, changes certain states, and needs to refresh the page to re-render the page. Such as: user login successful, addition, deletion, update, etc.
location.reload();
this.$router.go(0); Anyone who has used it knows that the first two force the page to refresh, which will cause a brief flicker and a poor user experience.
<template> <div id="app"> <router-view v-if="isRouterAlive"></router-view> </div> </template> <script> export default { name: 'App', provide () { //Provide variables in the parent component and inject variables in the child component through inject. return { reload: this.reload } }, data() { return { isRouterAlive: true //Variable that controls whether the view is displayed} }, methods: { reload () { this.isRouterAlive = false; //Close first, this.$nextTick(function () { this.isRouterAlive = true; //Open again}) } }, } </script> Next, we can write this in the component that needs to refresh the page: export default { inject:['reload'], //Inject the reload method in App data () { return { ....... } }, Use in the code block that needs to refresh the page: This concludes this article about Vue's three methods of refreshing the page. For more relevant Vue refresh page content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: Docker-compose steps to configure the spring environment
question: The following error occurred when insta...
A few days ago, I exchanged some knowledge about ...
Directly code: select 'bigint unsigned' a...
Table of contents 1. Basic theory 1.1 Transaction...
Table of contents 1. Front-end routing implementa...
MySQL filtering timing of where conditions and ha...
Vue bus mechanism (bus) In addition to using vuex...
This article shares the specific code of Vue+expr...
In the process of learning CSS3, I found that man...
1: Tag selector The tag selector is used for all ...
Detailed explanation of linux touch command: 1. C...
Before introducing the GROUP BY and HAVING clause...
<br />Previous Web Design Tutorial: Web Desi...
Today is another very practical case. Just hearin...
Preface: Fully encapsulating a functional module ...