当前位置:网站首页>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 :
边栏推荐
- COMP5216 Mobile Computing Assignment 1 - Extending ToDoList app
- Kubernetes essential tools: 2021
- Today, I met a "migrant worker" who took out 38K from Tencent, which let me see the ceiling of the foundation
- Turtle cartography
- Web3 decentralized storage ecological landscape
- Gui+sqlserver examination system
- Notes on flowus
- Leetcode topic [array] -283- move zero
- 去中心化NFT交易协议将击败OpenSea
- 玩轉Linux,輕松安裝配置MySQL
猜你喜欢

20:第三章:开发通行证服务:3:在程序中,打通redis服务器;(仅仅是打通redis服务器,不涉及具体的业务开发)

Discussion: the next generation of stable coins

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

Discover K8E: minimalist kubernetes distribution

Implementation of MySQL master-slave architecture

关于FlowUs这一款国民好笔记

Classical synchronization problem

Set up your own website (16)

玩转Linux,轻松安装配置MySQL

SIGIR 2022 | University of Hong Kong and others proposed the application of hypergraph comparative learning in Recommendation System
随机推荐
proxy
Romance of the Three Kingdoms: responsibility chain model
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!
Day10 daily 3 questions (3): String Matching in array
Jouer avec Linux et installer et configurer MySQL facilement
Call the random function to generate 20 different integers and put them in the index group of institute a
Microservice architecture practice: business management background and SSO design: SSO design
20:第三章:开发通行证服务:3:在程序中,打通redis服务器;(仅仅是打通redis服务器,不涉及具体的业务开发)
玩轉Linux,輕松安裝配置MySQL
What does the inner structure of the neural network "alchemy furnace" look like? An interpretation of the thesis by the doctor of Oxford University
Several forms of buffer in circuit
[qt learning notes]qt inter thread data communication and data sharing
She said she was tired! So tired! I want to change my career
Fgetc() reads content from file
Calculate a=1, a2=1/1=a1
Discussion: the next generation of stable coins
Platform management background and merchant menu resource management: Design of platform management background data service
对NFT市场前景的7个看法
Vibrating liquid quantity detecting device
Count the number of each vowel letter in the string