当前位置:网站首页>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 :
边栏推荐
- ACL 2022 | 基于神经标签搜索的零样本多语言抽取式文本摘要
- Cloud native 02: Alibaba cloud cloud efficient flow pipeline
- The function keeps the value of variable H to two decimal places and rounds the third digit
- Some explanations for latex CJK
- Environment setup mongodb
- Viewing the task arrangement ability of monorepo tool from turborepo
- SIGIR 2022 | 港大等提出超图对比学习在推荐系统中的应用
- 玩转Linux,轻松安装配置MySQL
- Toupper function
- Fire evacuation and self rescue... This safety production and fire training is full!
猜你喜欢

Viewing the task arrangement ability of monorepo tool from turborepo

ACL 2022 | zero sample multilingual extracted text summarization based on neural label search

Live broadcast preview | how can programmers improve R & D efficiency? On the evening of June 21, the video number and station B will broadcast live at the same time. See you or leave!

探讨:下一代稳定币

Constructors and Destructors

数字藏品与NFT到底有何区别

Getting started with mongodb

Notes on flowus

Decentralized NFT transaction protocol will defeat opensea

Necessary decorator mode for 3 years' work
随机推荐
Viewing the task arrangement ability of monorepo tool from turborepo
Constructors and Destructors
Turtle cartography
Day10 daily 3 questions (2): count the number of the largest groups
Teach you to learn dapr - 1 The era of net developers
108. simple chat room 11: realize client group chat
[C language] static modifies local variables
What does the equals method compare? Who told you
Platform management background and merchant menu resource management: merchant registration management design
R329 (maix-ii-a (M2A) data summary
[Error] ld returned 1 exit status
LeetCode Algorithm 24. Exchange the nodes in the linked list in pairs
GUI+SQLServer考试系统
Army chat -- registration of Registration Center
[recommendation system learning] recommendation system architecture
Fgetc() reads content from file
Platform management background and merchant menu resource management: access control design of platform management background
Jouer avec Linux et installer et configurer MySQL facilement
Junit单元测试
去中心化NFT交易协议将击败OpenSea