This article example shares the specific code of Vue to implement the page caching function for your reference. The specific content is as follows Keep-alive is mainly used to jump from the list page to the detail page, and then when you click back, the page cache does not need to request resources again. 1. Configure routing in the router Define in meta whether the page needs to be cached import Vue from "vue"; import Router from "vue-router"; // Avoid redundant navigation to the current location const originalPush = Router.prototype.push Router.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) } Vue.use(Router); export default new Router({ base: '', routes: [{ path: "/", name: "index", component: () => import("@/layout"), redirect: '/login', children: [ { path: 'dutySheet', name: 'dutySheet', component: () => import("@/pages/Dashboard/DutySheet") }, { path: 'searchWord', name: 'searchWord', component: () => import("@/pages/dailyReportManage/searchWord/index"), meta: { keepAlive: true // Need to cache the page} }, // Matching maintenance { path: "troopAction", name: "troopAction", component: () => import("@/pages/Dashboard/TroopAction"), meta: { keepAlive: false // No cache required} }, ] }, ] }); 2. Configure APP.vue Use keep-alive for caching <keep-alive> <router-view v-if="$route.meta.keepAlive"></router-view> </keep-alive> <router-view v-if="!$route.meta.keepAlive"></router-view> 3. When you click the back button, just call the this.$router.back() method // return bacKBnt(){ this.$router.back() }, 4. Clear the cache Only jumps to the "exhibitionWord" or "exhibitionWeekWord" page are cached, and jumps to other pages do not need to be cached. beforeRouteLeave(to, from, next) { if (to.name == 'exhibitionWord' || to.name == 'exhibitionWeekWord') { // Route name to be cached from.meta.keepAlive = true next() }else{ from.meta.keepAlive = false next() } }, The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to install OpenSuse on virtualbox
>>: Detailed explanation of the difference between MySQL normal index and unique index
You can go to the Ubuntu official website to down...
I have been using the CentOS purchased by Alibaba...
Preface Slow query log is a very important functi...
The article mainly records the simple installatio...
<br />Related articles: innerHTML HTML DOM i...
Table of contents 1. Background: 2. Design ideas:...
Reflections on the two viewpoints of “people-orie...
Preface The Linux system is controlled by the sys...
1. When the width of the adjacent floating layer o...
1. Download First of all, I would like to recomme...
Table of contents 1. Picture above 2. User does n...
Add secure_file_priv = ' '; then run cmd ...
We are not discussing PHP, JSP or .NET environmen...
We often encounter this situation in front-end de...
The official source code of monaco-editor-vue is ...