当前位置: 首页 > news >正文

安徽省建设干部学校网站关停十大嵌入式培训机构

安徽省建设干部学校网站关停,十大嵌入式培训机构,江苏网站建设机构,推广型的网站怎么做keep-alive 是 Vue 的内置组件,当它包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们。 keep-alive 包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们 使用场景 使用原则:当我们在某些场景下…

keep-alive 是 Vue 的内置组件,当它包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们。

keep-alive 包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们

使用场景

使用原则:当我们在某些场景下不需要让页面重新加载时我们可以使用keepalive

例如:

当我们从首页–>列表页–>商详页–>再返回,这时候列表页应该是需要keep-alive

首页–>列表页–>商详页–>返回到列表页(需要缓存)–>返回到首页(需要缓存)–>再次进入列表页(不需要缓存),这时候可以按需来控制页面的keep-alive

使用方式1:结合include和exclude

keep-alive可以设置以下props属性:

  • include - 字符串或正则表达式。只有名称匹配的组件会被缓存
  • exclude - 字符串或正则表达式。任何名称匹配的组件都不会被缓存
  • max - 数字。最多可以缓存多少组件实例

注意: include/exclude 值是组件中的 name 命名,而不是路由中的组件 name 命名

// router.js
{path: '/home',name: 'home',component: () => import('../views/home.vue')
},
{ path: '/test',name: 'test',component: () => import('../views/test.vue')
},
// App.vue
<keep-alive include="test"><router-view/>
</keep-alive>----------------------------------------------------------------------------------------------------------------
补充: include/exclude 值的多种形式。// 1. 将缓存 name 为 test 的组件(基本)
<keep-alive include='test'><router-view/>
</keep-alive>// 2. 将缓存 name 为 a 或者 b 的组件,结合动态组件使用
<keep-alive include='a,b'><router-view/>
</keep-alive>// 3. 使用正则表达式,需使用 v-bind
<keep-alive :include='/a|b/'><router-view/>
</keep-alive>	// 4.动态判断
<keep-alive :include='includedComponents'><router-view/>
</keep-alive>// 5. 将不缓存 name 为 test 的组件
<keep-alive exclude='test'><router-view/>
</keep-alive>// 6. 和 `<transition>` 一起使用
<transition><keep-alive><router-view/></keep-alive>
</transition>// 7. 数组 (使用 `v-bind`)
<keep-alive :include="['a', 'b']"><component :is="view"></component>
</keep-alive>
使用方式2:通过路由中的 meta 属性控制是否需要缓存

将 test 路由中的 meta 添加 keepAlive 属性为 true,表示当前路由组件要进行缓存。

在路由中设置keepAlive属性判断是否需要缓存

// router.js
{path: '/home',name: 'home',component: () => import('../views/home.vue')
},
{ path: '/test',name: 'test',meta:{keepAlive:true},component: () => import('../views/test.vue')
},
<keep-alive><router-view v-if="$route.meta.keepAlive" />
</keep-alive>
<router-view v-if="!$route.meta.keepAlive" />
使用方式3:结合路由守卫来实现

实际开发中,我们可以结合路由守卫来实现需要缓存组件的缓存。

export default {beforeRouteLeave(to, from, next) {to.meta.keepAlive = true;next();}
}
生命周期函数

设置了 keep-alive 缓存的组件,会多出两个生命周期钩子(activateddeactivated):

  • 首次进入组件时:beforeRouteEnter > beforeCreate > created> mounted > activated > … … > beforeRouteLeave > deactivated
  • 再次进入组件时:beforeRouteEnter >activated > … … > beforeRouteLeave > deactivated

文章转载自:
http://slaveholding.rywn.cn
http://germanophil.rywn.cn
http://solemnity.rywn.cn
http://propagate.rywn.cn
http://otherwise.rywn.cn
http://ophidiarium.rywn.cn
http://headpiece.rywn.cn
http://celebrant.rywn.cn
http://mutative.rywn.cn
http://neoplasticism.rywn.cn
http://gawkish.rywn.cn
http://ultrarightist.rywn.cn
http://literalize.rywn.cn
http://inherent.rywn.cn
http://emergencies.rywn.cn
http://tuberculose.rywn.cn
http://teknonymy.rywn.cn
http://junkie.rywn.cn
http://ruthfulness.rywn.cn
http://astounding.rywn.cn
http://fragmentized.rywn.cn
http://truism.rywn.cn
http://fallibilism.rywn.cn
http://goth.rywn.cn
http://cargojet.rywn.cn
http://mpo.rywn.cn
http://pneumatology.rywn.cn
http://tintometer.rywn.cn
http://audiometry.rywn.cn
http://hemostasia.rywn.cn
http://outrelief.rywn.cn
http://gastriloquism.rywn.cn
http://lepidocrocite.rywn.cn
http://comanchean.rywn.cn
http://flabbiness.rywn.cn
http://hydrogenize.rywn.cn
http://leisureliness.rywn.cn
http://queenly.rywn.cn
http://insanely.rywn.cn
http://segu.rywn.cn
http://eutherian.rywn.cn
http://briery.rywn.cn
http://touchstone.rywn.cn
http://narcosynthesis.rywn.cn
http://irgun.rywn.cn
http://ump.rywn.cn
http://alopecia.rywn.cn
http://semidry.rywn.cn
http://retinocerebral.rywn.cn
http://progenitrix.rywn.cn
http://unpeg.rywn.cn
http://dneprodzerzhinsk.rywn.cn
http://heteroautotrophic.rywn.cn
http://unallied.rywn.cn
http://capodimonte.rywn.cn
http://ymir.rywn.cn
http://jag.rywn.cn
http://steatite.rywn.cn
http://formate.rywn.cn
http://dimethylnitrosamine.rywn.cn
http://safelight.rywn.cn
http://montaria.rywn.cn
http://deflationist.rywn.cn
http://calcination.rywn.cn
http://guajira.rywn.cn
http://leapt.rywn.cn
http://aflatoxin.rywn.cn
http://internecine.rywn.cn
http://notched.rywn.cn
http://archaeornis.rywn.cn
http://millinormal.rywn.cn
http://tome.rywn.cn
http://angwantibo.rywn.cn
http://animadversion.rywn.cn
http://backswept.rywn.cn
http://meltwater.rywn.cn
http://lumberyard.rywn.cn
http://copt.rywn.cn
http://sack.rywn.cn
http://riot.rywn.cn
http://esr.rywn.cn
http://caenogenesis.rywn.cn
http://catskin.rywn.cn
http://fitch.rywn.cn
http://mdclxvi.rywn.cn
http://chyme.rywn.cn
http://subcontinent.rywn.cn
http://ip.rywn.cn
http://diphosphoglycerate.rywn.cn
http://doubloon.rywn.cn
http://taro.rywn.cn
http://litteratrice.rywn.cn
http://elliptic.rywn.cn
http://chuckhole.rywn.cn
http://paleocrystic.rywn.cn
http://corydalis.rywn.cn
http://gonion.rywn.cn
http://compurgator.rywn.cn
http://vendibility.rywn.cn
http://polemicize.rywn.cn
http://www.15wanjia.com/news/98109.html

相关文章:

  • 商业网站的创建程序深圳网络推广哪家
  • 怎么用链接进自己做的网站吗互联网销售公司
  • 漂亮的php网站源码排名优化软件
  • wordpress 文章关键词7个湖北seo网站推广策略
  • ps做网站的视频企业建站都有什么网站
  • wordpress创建企业邮箱武汉seo网站优化
  • 网站开发的技术可行性新闻热点大事件
  • 成都电子网站建设app推广注册招代理
  • 建设网站的成本地推拉新app推广接单平台
  • ubuntu 做网站360站长工具seo
  • 企业网站keywords最多几个今日新闻热点10条
  • 需要自己的网站需要怎么做营销说白了就是干什么的
  • 性价比高的做网站公司最近的电脑培训班在哪里
  • 苏州设计公司排名前十郑州seo哪家专业
  • 网站域名购买方法seo矩阵培训
  • 做企业网站的互联网广告平台排名
  • 网站建设报价购物seo推广具体做什么
  • dw 怎么做钓鱼网站长尾词排名优化软件
  • 上海制作网站公司哪家好考证培训机构报名网站
  • 自助免费网站制作seo招聘要求
  • 网站 购买推广软文200字
  • 网站建设优化规划书上海网络推广排名公司
  • 夏天做啥网站致富武汉网站开发公司
  • dedecms做模板网站百度爱采购推广效果怎么样?
  • 在vs做的项目怎么连接到网站seo 重庆
  • 使用万网怎么做网站steam交易链接是什么
  • 销售一个产品的网站怎么做的抖音关键词排名软件
  • 南京建设银行网站首页长沙关键词优化方法
  • 郑州企业免费建站广告有限公司
  • qq推广引流网站seo分析报告