当前位置:网站首页>vue--vuerouter缓存路由组件
vue--vuerouter缓存路由组件
2022-06-26 16:50:00 【春风霓裳】
作用:能保存组件原来的数据!!!(注意:时同一个父路由路径下切换才行)
在其父组件中使用 标签,include的值为组件名!!!
<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的值为组件名!!! -->
<keep-alive include="News">
<router-view></router-view>
</keep-alive>
缓存多个组件路由
<keep-alive :include="['News','Message']">
<router-view></router-view>
</keep-alive>
代码演示:
<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的值为组件名!!! --> <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>
路由index.js
// 该文件用于专门创建路由器 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' // 创建并暴露一个路由器 export default new VueRouter({
routes:[
{
name:'guanyu', path:'/about', component:About, children:[
{
// 二级路由路径不能加/ path:'message', component:Message, children:[
{
name:'xiangqing', // path:'detail/:id/:title', path:'detail', component:Detail, // props的第一种写法,值为对象, // 该对象中的所有key-value都会以props的形式传给Detail组件 // props:{
a:1,b:'hello'}
// props的第二种写法,值为布尔值,若该布尔值为真 // 就会把该路由组件收到的所有params参数,以props的形式传给Detail组件 // props:true // props的第三种写法,值为函数 props($route){
return {
id:$route.query.id,title:$route.query.title}
}
}
]
}
]
},
{
path:'/home', component:Home, children:[
{
// 二级路由路径不能加/
path:'news',
component:News
},
{
// 二级路由路径不能加/ path:'message', component:Message, children:[
{
name:'xiangqing', // path:'detail/:id/:title', path:'detail', component:Detail, // props的第一种写法,值为对象, // 该对象中的所有key-value都会以props的形式传给Detail组件 // props:{
a:1,b:'hello'}
// props的第二种写法,值为布尔值,若该布尔值为真 // 就会把该路由组件收到的所有params参数,以props的形式传给Detail组件 // props:true // props的第三种写法,值为函数 props($route){
return {
id:$route.query.id,title:$route.query.title}
}
}
]
}
]
}
]
})
结果:
边栏推荐
- 进军AR领域,这一次罗永浩能成吗?
- Classical synchronization problem
- [latex bearer] use tables in \title (error \begin doesn't match its definition.)
- [suggested collection] 11 online communities suitable for programmers
- Web3 decentralized storage ecological landscape
- Leetcode 1169. Query invalid transactions (if the amount of data is small, this problem still needs to be solved by violent enumeration)
- Interpretation of cloud native microservice technology trend
- Record the use process of fenics
- Niuke Xiaobai monthly race 50
- 量化合约系统开发分析案例丨合约量化系统开发方案详解
猜你喜欢

Platform management background and merchant menu resource management: access control design of platform management background

A simple membership card management system based on Scala

MS|谢黎炜组发现混合益生菌制剂及其代谢产物可缓解结肠炎

Leetcode 1170. Frequency of occurrence of the minimum letter of the comparison string (yes, solved)

Leetcode 1170. 比较字符串最小字母出现频次(可以,已解决)

ACL 2022 | 基于神经标签搜索的零样本多语言抽取式文本摘要

Teach you to learn dapr - 2 Must know concept

类型多样的石膏PBR多通道贴图素材,速来收藏!

Teach you to learn dapr - 3 Run the first with dapr Net program

直播预告|程序员进击,如何提升研发效能?6月21日晚视频号、B站同步直播,不见不散!
随机推荐
关于FlowUs这一款国民好笔记
Community ownership of NFT trading market is unstoppable
进军AR领域,这一次罗永浩能成吗?
去中心化NFT交易协议将击败OpenSea
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
proxy
What is the difference between digital collections and NFT
num[i]++
Leetcode 1169. 查询无效交易(如果数据量不大,这种题还是得暴力枚举解决)
Some explanations for latex CJK
Alibaba's "high concurrency" tutorial "basic + actual combat + source code + interview + Architecture" is a god class
20:第三章:开发通行证服务:3:在程序中,打通redis服务器;(仅仅是打通redis服务器,不涉及具体的业务开发)
建立自己的网站(16)
Find all primes less than or equal to Lim, store them in AA array, and return the number of primes
Platform management background and merchant menu resource management: access control design of platform management background
Today, I met a "migrant worker" who took out 38K from Tencent, which let me see the ceiling of the foundation
Programmer's essential toolkit, please collect!
Byte interview: two array interview questions, please accept
C语言所有知识点小结
Stm32f103c8t6 realize breathing lamp code