博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue中使用keep-alive实现tab
阅读量:3933 次
发布时间:2019-05-23

本文共 1426 字,大约阅读时间需要 4 分钟。

当组件在keep-alive中被切换时,缓存一次后mounted就不执行了,而activated和deactivated这两个钩子函数会被执行。

activated:被 keep-alive 缓存的组件激活时调用。
deactivated:被 keep-alive 缓存的组件停用时调用。

keep-alive还可以接受两个参数,include和exclude,允许组件有条件地缓存。

二者都可以用字符串或正则表达式。
include:只有匹配的组件会被缓存。
exclude:任何被匹配的组件将不会被缓存

先做一个简单的tab:

结果:

在这里插入图片描述

代码:

路由:

主要要设置 meta:{ keepAlive:true }

export default new Router({
mode: 'history', base: process.env.BASE_URL, routes: [ {
path: '/', name: 'home', component: Home, children:[ {
path: '/', name:'HelloWorld', component: () => import( './components/HelloWorld.vue'), meta:{
keepAlive:true } }, {
path: '/HelloWorld', name:'HelloWorld', component: () => import( './components/HelloWorld.vue'), meta:{
keepAlive:true } }, {
path: '/tabContent', name:'tabContent', component: () => import( './components/tabContent.vue'), meta:{
keepAlive:true } }, ] }, ]})

include用法:

注意:匹配首先检查组件自身的 name 选项,如果 name 选项不可用,则匹配它的局部注册名称 (父组件 components 选项的键值)。匿名组件不能被匹配

转载地址:http://hwrgn.baihongyu.com/

你可能感兴趣的文章
qtcreator4.4.1中cmake 与cmake3.5.1本身generate出来的setting是有区别的解决方法
查看>>
CMake Useful Variables/Logging Useful Variables
查看>>
使用cmake建立工程链接OPENNI2
查看>>
ubuntu下解决csdn网页打不开的问题
查看>>
uninstall software on ubuntu
查看>>
install kinnect senor on ubuntu
查看>>
calibrate kinnect v1 on ubuntu
查看>>
flann中关于数据的stride
查看>>
cv::Mat ptr 和 at 注意事项
查看>>
cuda更新过后, findcuda找不到怎么办?
查看>>
cast shared_ptr to shared_ptr
查看>>
Elastic Job入门示例-实现DataflowJob接口
查看>>
Elastic Job入门示例-Console控制台
查看>>
Elastic Job入门示例-实现原理介绍
查看>>
HTTP状态码对照表
查看>>
Spring Cloud Feign 服务间调用 -超时
查看>>
MySQL 中事务、事务隔离级别详解
查看>>
Telnet 命令在Windows与Linux/Unix下的区别
查看>>
Java传统IO / NIO基础知识
查看>>
Netty3- 入门示例
查看>>