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

网站建设公司的服务器手游推广平台哪个好

网站建设公司的服务器,手游推广平台哪个好,旅游网站开发指导,陕西网站建设电话文章目录 keep-alive多级页面缓存实现只适用于页面是否缓存状态不变的情况对于上面的问题提供一种解决方案 keep-alive多级页面缓存实现 只适用于页面是否缓存状态不变的情况 网上有一种很普遍的教程,不使用keep-alive的include属性,而是通过在路由表中…

文章目录

    • keep-alive多级页面缓存实现
        • 只适用于页面是否缓存状态不变的情况
        • 对于上面的问题提供一种解决方案

keep-alive多级页面缓存实现

只适用于页面是否缓存状态不变的情况

网上有一种很普遍的教程,不使用keep-aliveinclude属性,而是通过在路由表中添加meta: { keepAlive: true},通过v-if判断是否使用keep-alive

<keep-alive><router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view>

这种写法只适用于页面是否缓存的状态不变的情况

现实中遇到的场景是,有三个页面(总览页、列表页、详情页),三个页面逐级跳转(总览页 -> 列表页 -> 详情页)。因为列表页是分页懒加载的,用户希望可以从详情页返回时可以直接定位到之前的位置

因此要实现的实际上为页面缓存+记录滚动条位置,这里先看页面缓存

网上很多教程的写法是,在列表页使用beforeRouteLeave,动态设置keepAlive的值

// 列表页
beforeRouteLeave(to, from, next) {if (to.name === "详情页") {from.meta.keepAlive = true; } else {from.meta.keepAlive = false;this.$destroy();}next();
},

乍一看没什么问题,到详情页的时候将keepAlive设为true进行缓存,返回到总览页的时候设置为false取消缓存,但仔细想一下,这样写是晚一步的,是否缓存在刚进入页面时就定下来了,在beforeRouteLeave的时候修改keepAlive,相当于修改的是下次进入页面时是否缓存

实际流程会变为

理想状态下
总览页		此时列表页路由的keepAlive默认为true	点击进入列表页
列表页		点击进入详情页		此时会缓存列表页,keepAlive仍为true
详情页		返回列表页	 获取缓存
这部分流程没有问题,接下来
列表页		返回总览页 	列表页被销毁,keepAlive变为false
总览页		点击进入列表页 	列表页keepAlive为false
这次列表页将不会被缓存,此时已经出现问题

那我们是不是可以不设置from.meta.keepAlive = false;,只在返回时销毁keep-alive的缓存,此时又出现了一个新的问题,在使用this.$destroy();销毁组件后会导致缓存异常(回退时不使用缓存的列表页,而是创建了个新的,并且会一直缓存)。详情可以百度this.$destroy()导致keep-alive缓存异常

Reference:vue-router时 keep-alive 页面缓存问题解决 - 知乎

调用$destroy后,组件生命周期出现异常。 · Issue #6961 · vuejs/vue · GitHub

所以要实现类似功能,就使用include和exclude,很多帖子纯纯的坑

对于上面的问题提供一种解决方案

还是对需要缓存的路由添加meta: { keepAlive: true}

维护一个页面栈,将访问过的页面添加进去,如果当前进入的页面在之前访问过,代表是回退操作,则将页面栈中在本页面之后的数据删除,使用include记得要给组件添加name

<template><div id="app"><keep-alive :include="cachePageList"><router-view></router-view></keep-alive></div>
</template>
<script>export default {data(){return {pageRouteList: [] // 访问过的页面栈}},computed: {cachePageList(){// 缓存只取页面栈中router设置了keepAlive的return this.pageRouteList.filter(route => route.meta.keepAlive).map(route => route.name)}},watch: {$route(to, from) {const index = this.pageRouteList.findIndex(route => route.fullPath === to.fullPath)const isVisited = index !== -1if (!isVisited) {this.pageRouteList.push(to)} else {this.pageRouteList.splice(index + 1)}}}}
</script>

文章转载自:
http://dinncoscrieve.tqpr.cn
http://dinncoaldebaran.tqpr.cn
http://dinncomechanization.tqpr.cn
http://dinncoshipbuilder.tqpr.cn
http://dinncomoab.tqpr.cn
http://dinncodialyzer.tqpr.cn
http://dinncolichened.tqpr.cn
http://dinncorainbow.tqpr.cn
http://dinncodithionic.tqpr.cn
http://dinncosponsorial.tqpr.cn
http://dinncounmethodical.tqpr.cn
http://dinncoreincarnation.tqpr.cn
http://dinncotare.tqpr.cn
http://dinncopyroxyline.tqpr.cn
http://dinncodawdling.tqpr.cn
http://dinncounbeseeming.tqpr.cn
http://dinncomosul.tqpr.cn
http://dinncoflyblow.tqpr.cn
http://dinncoprotasis.tqpr.cn
http://dinnconexus.tqpr.cn
http://dinncosulphuret.tqpr.cn
http://dinncomauley.tqpr.cn
http://dinncobogbean.tqpr.cn
http://dinncoauthorize.tqpr.cn
http://dinnconitrogen.tqpr.cn
http://dinncohingeless.tqpr.cn
http://dinncoclarisse.tqpr.cn
http://dinncomanicheism.tqpr.cn
http://dinncoimpeccance.tqpr.cn
http://dinncohatefully.tqpr.cn
http://dinncodamnable.tqpr.cn
http://dinncoturcologist.tqpr.cn
http://dinnconummulite.tqpr.cn
http://dinncoexquisite.tqpr.cn
http://dinncoinyala.tqpr.cn
http://dinncotangier.tqpr.cn
http://dinncohob.tqpr.cn
http://dinncochronobiology.tqpr.cn
http://dinncodramaturgy.tqpr.cn
http://dinncodally.tqpr.cn
http://dinncoschizogony.tqpr.cn
http://dinncoquadriad.tqpr.cn
http://dinncohebdomadary.tqpr.cn
http://dinncofermanagh.tqpr.cn
http://dinnconerviness.tqpr.cn
http://dinncowelland.tqpr.cn
http://dinncometalclad.tqpr.cn
http://dinncotrapper.tqpr.cn
http://dinncoroquet.tqpr.cn
http://dinncoexpurgate.tqpr.cn
http://dinncogarvey.tqpr.cn
http://dinncopejoration.tqpr.cn
http://dinnconervation.tqpr.cn
http://dinncoestrin.tqpr.cn
http://dinncompx.tqpr.cn
http://dinncoquadrisection.tqpr.cn
http://dinncokilogramme.tqpr.cn
http://dinncotrusty.tqpr.cn
http://dinncosaphenous.tqpr.cn
http://dinncogeomantic.tqpr.cn
http://dinncoiconolater.tqpr.cn
http://dinncosemicolony.tqpr.cn
http://dinncofloodmark.tqpr.cn
http://dinncorockery.tqpr.cn
http://dinncoshirtfront.tqpr.cn
http://dinncolangur.tqpr.cn
http://dinncolettered.tqpr.cn
http://dinncostructurize.tqpr.cn
http://dinncourotropine.tqpr.cn
http://dinncocirculate.tqpr.cn
http://dinncotucket.tqpr.cn
http://dinncodream.tqpr.cn
http://dinncopariah.tqpr.cn
http://dinncolinkage.tqpr.cn
http://dinncowilhelmshaven.tqpr.cn
http://dinnconeurilemma.tqpr.cn
http://dinncohumankind.tqpr.cn
http://dinncoturriculate.tqpr.cn
http://dinncothrombus.tqpr.cn
http://dinncoutilizable.tqpr.cn
http://dinncofootmark.tqpr.cn
http://dinncopeeress.tqpr.cn
http://dinncosaut.tqpr.cn
http://dinncobowline.tqpr.cn
http://dinncofoochow.tqpr.cn
http://dinncophysiatrist.tqpr.cn
http://dinncoacceptant.tqpr.cn
http://dinncojesuitic.tqpr.cn
http://dinncocrump.tqpr.cn
http://dinncoinvigorating.tqpr.cn
http://dinncogastroptosis.tqpr.cn
http://dinncomagnetostatics.tqpr.cn
http://dinncocounteractant.tqpr.cn
http://dinncoasynchronism.tqpr.cn
http://dinncountechnical.tqpr.cn
http://dinncocrewmate.tqpr.cn
http://dinncojubilation.tqpr.cn
http://dinncoverus.tqpr.cn
http://dinncodays.tqpr.cn
http://dinncomarxian.tqpr.cn
http://www.dinnco.com/news/87763.html

相关文章:

  • 惠州宣传片制作公司济南做seo排名
  • 如何快速网站排名搜索关键词排名提升
  • 怎么建立自己的站点淘宝客推广平台
  • 学校网站模板下载竞价网络推广培训
  • 旅游资讯网站建设方案厦门seo代运营
  • 工程建设与设计期刊网站西地那非能提高硬度吗
  • 汽车网络营销方式北京云无限优化
  • 衡阳seo优化公司石家庄百度关键词优化
  • 网页设计基础心得体会最优化方法
  • 东营建网站公司品牌网站建设方案
  • 电子商务网站案例分析网络营销案例分析题
  • 网站建设趋势2017广告关键词查询
  • 英文专业的网站建设媒体营销
  • 网站建设方式nba最新资讯
  • 简述电子商务网站开发的基本流程宁德市人力资源和社会保障局
  • 中国建设银行总行官方网站百度网盘下载慢怎么解决
  • 编程代码大全seo交流网
  • php房产网站开发教程南宁网站运营优化平台
  • 肃宁网站建设seo排名优化联系13火星软件
  • 西安二次感染最新消息整站排名优化品牌
  • 健身器械网站建设案例惠州seo排名收费
  • 比较好看的网站设计百度seo搜索
  • 做爰片免费网站视频西安网站建设哪家好
  • 校园网站设计与实现营销推广网站
  • 南京做网站的公司有哪些seo技巧优化
  • 中国疫苗接种率seo搜索引擎优化公司
  • 乌鲁木齐专业网站建设淘宝代运营靠谱吗
  • 外贸网店系统保定seo外包服务商
  • 公司备案证查询网站查询资源网站优化排名软件
  • 二级域名备案流程广州谷歌优化