Vue中的keep-alive应用

Snipaste_20210330_175949.jpg
keep-alive是后台管理系统中基本,他会缓存不活动的组件实例,而不是销毁它们。

应用:

          
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
<div> <keep-alive> <router-view v-if="$route.meta.keepAlive"></router-view> </keep-alive> <router-view v-if="!$route.meta.keepAlive"></router-view> </div>

VueRouter的代码

          
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
{ path: "/goodslist", name: "goodslist", component: () =>import("../views/goods/goodslist.vue"), meta: { keepAlive: true }, },

上面这段代码用来区分使用keep-alive的页面和非使用的页面。

实际情况有时候还会需要计入滚动条的位置。 这时要用到activated,deactivated生命周期

可以在全局变量中记录一个滚动条位置scrolly_table,在跳转页面时记录一下scrolly_table。

          
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
activated() { //进入时读取位置 console.log('进入', scrolly_table); this.$refs.table_list.bodyWrapper.scrollTop = scrolly_table; }, deactivated(){ //离开时记录位置 console.log('离开') },
(完)
vite创建vue3项目 eslint+prettier+stylelint
eslint+prettier+stylelint配置
My Weight Loss Experience
Lose weight again over the next three months
2023年终总结
2024新年快乐
这两月又看不少片
养蜂人,哥斯拉大战金刚2,热辣滚烫,毒舌律师,功夫熊猫4,破墓,飞驰人生2,新生,辐射,寄生兽
vue3.2 Keepalive踩坑
vite-plugin-vue-setup-extend 插件给script标签赋值name属性,小问题花费我一天找答案
Js数组排序,上移下移置顶置底
Js数组排序
等待你的评论