当前位置:网站首页>Vue--vuerouter cache routing component
Vue--vuerouter cache routing component
2022-06-26 17:10:00 【Spring wind neon clothes】
effect : It can save the original data of components !!!( Be careful : Only when switching under the same parent routing path )
Use... In its parent component label ,include The value of is the component name !!!
<ul>
<li>
<router-link active-class="active" to="/home/message">message</router-link>
</li>
<li>
<router-link active-class="active" to='/home/news'>news</router-link>
</li>
</ul>
<!-- include The value of is the component name !!! -->
<keep-alive include="News">
<router-view></router-view>
</keep-alive>
Cache multiple component routes
<keep-alive :include="['News','Message']">
<router-view></router-view>
</keep-alive>
Code demonstration :
<template> <div class="Home"> <h1>Home</h1> <ul> <li> <router-link active-class="active" to="/home/message">message</router-link> </li> <li> <router-link active-class="active" to='/home/news'>news</router-link> </li> </ul> <!-- include The value of is the component name !!! --> <keep-alive include="News"> <router-view></router-view> </keep-alive> </div> </template> <script> export default {
name:'Home', data(){
return{
}
}, methods:{
}
}
</script> <style scoped> .Home{
background-color: aqua;
}
</style>
route index.js
// This file is used to create routers import VueRouter from 'vue-router' import About from '../pages/About' import Home from '../pages/Home' import News from '../pages/News' import Message from '../pages/Message' import Detail from '../pages/Detail' // Create and expose a router export default new VueRouter({
routes:[
{
name:'guanyu', path:'/about', component:About, children:[
{
// The secondary routing path cannot be added / path:'message', component:Message, children:[
{
name:'xiangqing', // path:'detail/:id/:title', path:'detail', component:Detail, // props The first way to write , Value as object , // All... In this object key-value with props In the form of Detail Components // props:{
a:1,b:'hello'}
// props The second way to write , The value is Boolean , If the Boolean value is true // All messages received by the routing component will be sent params Parameters , With props In the form of Detail Components // props:true // props The third way of writing , The value is a function props($route){
return {
id:$route.query.id,title:$route.query.title}
}
}
]
}
]
},
{
path:'/home', component:Home, children:[
{
// The secondary routing path cannot be added /
path:'news',
component:News
},
{
// The secondary routing path cannot be added / path:'message', component:Message, children:[
{
name:'xiangqing', // path:'detail/:id/:title', path:'detail', component:Detail, // props The first way to write , Value as object , // All... In this object key-value with props In the form of Detail Components // props:{
a:1,b:'hello'}
// props The second way to write , The value is Boolean , If the Boolean value is true // All messages received by the routing component will be sent params Parameters , With props In the form of Detail Components // props:true // props The third way of writing , The value is a function props($route){
return {
id:$route.query.id,title:$route.query.title}
}
}
]
}
]
}
]
})
result :
边栏推荐
- What is flush software? Is it safe to open an account online?
- [recommendation system learning] recommendation system architecture
- [recommendation system learning] technology stack of recommendation system
- Detailed explanation of browser storage methods: the origin and difference of cookies, localstorage and sessionstorage
- [matlab project practice] prediction of remaining service life of lithium ion battery based on convolutional neural network and bidirectional long short time (cnn-lstm) fusion
- Environment setup mongodb
- The function keeps the value of variable H to two decimal places and rounds the third digit
- 经典同步问题
- Interpretation of cloud native microservice technology trend
- 【MATLAB项目实战】基于卷积神经网络与双向长短时(CNN-LSTM)融合的锂离子电池剩余使用寿命预测
猜你喜欢

Demonstrate to Xiaobai the case of sub database and sub table

7 views on NFT market prospect

vue--vuerouter缓存路由组件

QT 5.9.8 installation tutorial

Classical synchronization problem

Fire evacuation and self rescue... This safety production and fire training is full!

Getting started with mongodb

When I was in the library, I thought of the yuan sharing mode

Platform management background and merchant menu resource management: merchant registration management design

【MATLAB项目实战】基于卷积神经网络与双向长短时(CNN-LSTM)融合的锂离子电池剩余使用寿命预测
随机推荐
Convert the decimal positive integer m into the number in the forward K (2 < =k < =9) system and output it in bits
Calculate a=1, a2=1/1=a1
Platform management background and merchant menu resource management: merchant registration management design
分布式架构概述
分布式缓存/缓存集群简介
When I was in the library, I thought of the yuan sharing mode
Leetcode topic [array] -283- move zero
Toupper function
Decentralized NFT transaction protocol will defeat opensea
[C language] static modifies local variables
Today, I met a "migrant worker" who took out 38K from Tencent, which let me see the ceiling of the foundation
The function keeps the value of variable H to two decimal places and rounds the third digit
Interpretation of new plug-ins | how to enhance authentication capability with forward auth
The student record consists of student number and academic performance. The data of n students have been stored in the a structure array to find out the student record with the lowest performance
SQL injection for Web Security (3)
Demonstrate to Xiaobai the case of sub database and sub table
Programmer interview guide - self introduction
Junit单元测试
COMP5216 Mobile Computing Assignment 1 - Extending ToDoList app
Redis 概述整理