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
In the past, almost every website had a sitemap p...
In my last post I talked about how to make a web p...
Tomcat is an HTTP server that is the official ref...
This article shares the specific code of JavaScri...
Netease Kanyouxi official website (http://kanyoux...
Introduction to IPSec IPSec (Internet Protocol Se...
1. Introduction Presto is an open source distribu...
Table of contents 1. Install Vue scaffolding 2. C...
1. Unzip nginx-1.8.1.tar.gz 2. Unzip fastdfs-ngin...
IMG tag basic analysis In HTML5, the img tag has ...
1. Download the virtual machine Official download...
MySQL is a multi-user managed database that can a...
Table of contents Preface 1. Paste Events and Cli...
JavaScript now releases a new version every year,...
Preface MySQL query uses the select command, and ...