当前位置:网站首页>147 set whether to cache by using the routing meta information - use of include and exclude - use of activated and deactivated
147 set whether to cache by using the routing meta information - use of include and exclude - use of activated and deactivated
2022-07-24 20:04:00 【longfei815】
Stop recording as follows :

Home.vue Code :
About.vue Code :

router/index.js Code :
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
Vue.use(VueRouter)
// meta Object can define some path related parameter configurations . It is called routing meta information
// Acquisition of route meta information attributes : $route.meta. Property name
// $route When the routing object of the path
// $router The complete object of the route
const routes = [
{
path: '/',
name: 'Home',
component: Home,
meta: {
num: 30,
isKeep:true
}
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),
meta: {
num: 50,
isKeep: false
}
},
{
path: '/user',
component: () => import(/* webpackChunkName: "about" */ '../views/User.vue'),
meta: {
num: 50,
isKeep: true
}
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router
App.vue Code :
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link> |
<router-link to="/user">User</router-link>
</div>
<!-- keep-alive Do component level caching , The principle is : Do not let components be destroyed and recreated -->
<!-- demand : / With cache /about There is no cache
visit / $route.meta.isKeep The value of is true, Two router-view Just show , Yes keep-alive the . So there is cache
visit /about $route.meta.isKeep The value of is false, Two router-view Only show no keep-alive the . So there is no cache
-->
<!-- <keep-alive>
<router-view v-if="$route.meta.isKeep"/>
</keep-alive>
<router-view v-if="!$route.meta.isKeep"/> -->
<!-- :include Specify cached components -->
<keep-alive :include="['Home']">
<router-view />
</keep-alive>
<!-- The values in the array , Is in the component name The value of the property -->
<!-- :exclude Specify components without cache -->
<!-- <keep-alive :exclude="['Home']">
<router-view />
</keep-alive> -->
</div>
</template>
<style lang="less">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
// text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
</style>

The effect is as follows :

边栏推荐
- Sword finger offer 42. maximum sum of continuous subarrays
- YouTube "label products" pilot project launched
- Review the code implementation of memcpy function
- Virbox compiler, which supports source code encryption of the whole platform and architecture
- Sword finger offer 40. minimum number of K
- Thymeleaf application notes
- MySQL advanced 2
- Substr and substring function usage in SQL
- Leetcode652 finding duplicate subtrees
- Talk about your transformation test development process
猜你喜欢
![微服务架构 | 服务监控与隔离 - [Sentinel] TBC...](/img/28/8ca90e9dbd492688e50446f55959ff.png)
微服务架构 | 服务监控与隔离 - [Sentinel] TBC...

Implementation of OA office system based on JSP

Modbus communication protocol specification (Chinese) sharing

ATL container - catlmap, crbmap

02 | environment preparation: how to install and configure a basic PHP development environment under windows?

【校招面经】8道指针面试真题,快来检测自己掌握了几道。

Original reverse compensation and size end

The ark compiler is coming. What about APK reinforcement

Getting started with COM programming 1- creating projects and writing interfaces
Siyuan notes V2.1.2 synchronization problem
随机推荐
Redis basic knowledge, application scenarios, cluster installation
Ask a question: is there an error msg = ora-04036: instance usage when using CDC to monitor oracle
Sword finger offer 46. translate numbers into strings
2019 Hangzhou Electric Multi School Game 7 6651 final exam [Law + thinking]
How to view the execution plan of a stored procedure in Youxuan database
Sword finger offer 47. the maximum value of gifts
Browser local storage webstroage
Thinking of @requestbody caused by hi and hello requests
Leetcode652 finding duplicate subtrees
Cmake series tutorial 1- initial cmake
Leetcode 146: LRU cache
Setting up a dual machine debugging environment for drive development (vs2017)
About the largeheap attribute
Redis common configuration description
Prevent static decompilation, dynamic debugging and plug-in
从码农转型大音乐家,你只差这些音乐处理工具
Day 6 (array example)
day 1
Hide the middle digit of ID number
Convolutional neural network CNN