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

学院的网站怎么做广西网站建设路

学院的网站怎么做,广西网站建设路,网站功能优化,深圳网页制作费用最近有客户反映我们系统按条件查询完列表进入详情页后再返回列表页时页面没有展示他查询的那条数据,而是进入页面一贯会展示按无条件查询的数据,希望我们能对列表做查询缓存,那咱们就用keep-alive来实现一下 AppMain.vue include 属性绑定一个…

最近有客户反映我们系统按条件查询完列表进入详情页后再返回列表页时页面没有展示他查询的那条数据,而是进入页面一贯会展示按无条件查询的数据,希望我们能对列表做查询缓存,那咱们就用keep-alive来实现一下

AppMain.vue

include 属性绑定一个数组,数组里是打开需要缓存的路由name

<template><section class="app-main"><transition name="fade-transform" mode="out-in"><keep-alive :include="cachedViews"><router-view :key="key" /></keep-alive></transition></section>
</template>
<script>
export default {name: 'AppMain',computed: {cachedViews() {return this.$store.state.tagsView.cachedViews},key() {return this.$route.path}}
}
</script>

store文件夹下的getters.js

const getters = {visitedViews: state => state.tagsView.visitedViews,cachedViews: state => state.tagsView.cachedViews,
}
export default getters

store文件夹下的modules文件夹中创建tagsView.js文件

const state = {visitedViews: [], //所有访问过的路由参数cachedViews: [] // 需要可缓存的所有已访问路由name
}const mutations = {ADD_VISITED_VIEW: (state, view) => {if (state.visitedViews.some(v => v.path === view.path)) returnstate.visitedViews.push(Object.assign({}, view, {title: view.meta.title || 'no-name'}))},ADD_CACHED_VIEW: (state, view) => {if (state.cachedViews.includes(view.name)) returnif (!view.meta.noCache) {state.cachedViews.push(view.name)}},DEL_VISITED_VIEW: (state, view) => {for (const [i, v] of state.visitedViews.entries()) {if (v.path === view.path) {state.visitedViews.splice(i, 1)break}}},DEL_CACHED_VIEW: (state, view) => {const index = state.cachedViews.indexOf(view.name)index > -1 && state.cachedViews.splice(index, 1)},DEL_OTHERS_VISITED_VIEWS: (state, view) => {state.visitedViews = state.visitedViews.filter(v => {return v.meta.affix || v.path === view.path})},DEL_OTHERS_CACHED_VIEWS: (state, view) => {const index = state.cachedViews.indexOf(view.name)if (index > -1) {state.cachedViews = state.cachedViews.slice(index, index + 1)} else {state.cachedViews = []}},DEL_ALL_VISITED_VIEWS: state => {// keep affix tagsconst affixTags = state.visitedViews.filter(tag => tag.meta.affix)state.visitedViews = affixTags},DEL_ALL_CACHED_VIEWS: state => {state.cachedViews = []},UPDATE_VISITED_VIEW: (state, view) => {for (let v of state.visitedViews) {if (v.path === view.path) {v = Object.assign(v, view)break}}}
}const actions = {addView({ dispatch }, view) {dispatch('addVisitedView', view)dispatch('addCachedView', view)},addVisitedView({ commit }, view) {commit('ADD_VISITED_VIEW', view)},addCachedView({ commit }, view) {commit('ADD_CACHED_VIEW', view)},delView({ dispatch, state }, view) {return new Promise(resolve => {dispatch('delVisitedView', view)dispatch('delCachedView', view)resolve({visitedViews: [...state.visitedViews],cachedViews: [...state.cachedViews]})})},delVisitedView({ commit, state }, view) {return new Promise(resolve => {commit('DEL_VISITED_VIEW', view)resolve([...state.visitedViews])})},delCachedView({ commit, state }, view) {return new Promise(resolve => {commit('DEL_CACHED_VIEW', view)resolve([...state.cachedViews])})},delOthersViews({ dispatch, state }, view) {return new Promise(resolve => {dispatch('delOthersVisitedViews', view)dispatch('delOthersCachedViews', view)resolve({visitedViews: [...state.visitedViews],cachedViews: [...state.cachedViews]})})},delOthersVisitedViews({ commit, state }, view) {return new Promise(resolve => {commit('DEL_OTHERS_VISITED_VIEWS', view)resolve([...state.visitedViews])})},delOthersCachedViews({ commit, state }, view) {return new Promise(resolve => {commit('DEL_OTHERS_CACHED_VIEWS', view)resolve([...state.cachedViews])})},delAllViews({ dispatch, state }, view) {return new Promise(resolve => {dispatch('delAllVisitedViews', view)dispatch('delAllCachedViews', view)resolve({visitedViews: [...state.visitedViews],cachedViews: [...state.cachedViews]})})},delAllVisitedViews({ commit, state }) {return new Promise(resolve => {commit('DEL_ALL_VISITED_VIEWS')resolve([...state.visitedViews])})},delAllCachedViews({ commit, state }) {return new Promise(resolve => {commit('DEL_ALL_CACHED_VIEWS')resolve([...state.cachedViews])})},updateVisitedView({ commit }, view) {commit('UPDATE_VISITED_VIEW', view)}
}export default {namespaced: true,state,mutations,actions
}

最后

可以找个组件试一下,我这边已经实现了,效果可以自己去印证一下

export default {// 组件里一定要加上这个name,如果不需要缓存那就可以不要这个// 这个name一定要写对,要和定义的路由name一样// 如果不知道是什么可以在ADD_CACHED_VIEW打印一下view.namename: "Menu",
}
http://www.yayakq.cn/news/160320/

相关文章:

  • 购物网站建设开发费用分析0建设营销型网站步骤
  • ic网站建设做百度网站好吗
  • 国外能下载模板的网站龙岩e龙岩网
  • 家具公司网站模板免费网页app一键生成软件
  • 电商网站开发计划深圳网站建设制作企业
  • 可信网站代码国外优秀的设计网站
  • 企业网站怎样做优化大岭山网站
  • 办公室装修专业网站2022世界500强企业排名
  • 买了vps后怎么安装Wordpress网站推广的优化
  • 开发网站合作协议登录百度账号注册
  • 网站规划管理系统辽宁住房和城乡建设部网站
  • 深圳医院网站建设石材石料网站搭建教程
  • 我做的网站怎么打开很慢织梦cms通用蓝白简介大气企业网站环保科技公司源码
  • 网站备案号格式说明书附近人才招聘市场
  • 青岛网站开发培训室内设计师培训哪里好
  • 跨境电商自己做网站卖衣服福田蒙派克空调滤芯在哪
  • 网站开发公司商业计划书wordpress添加新建标签页
  • 成都app程序开发优化型网站是模板
  • phpcms调用网站名称购买已备案域名
  • 中卫网站网站建设我的世界服务器赞助网站怎么做
  • 摄影网站备案装修公司报价
  • wordpress 漫画网站无锡网络公司无锡网站推广
  • 阿里云服务器win系统建站教程昆明建网站要多少钱
  • 网站字体 font-family户外运动网站模板
  • 酷炫网站设计领英怎么注册公司主页
  • 肇庆网站快速排名优化哪个网站上可以做初中数学题
  • 网站空间怎么备份平面设计的大专学校
  • 视频广告网站如果我的网站被百度收录了_以后如何做更新争取更多收录
  • 网站开发要学些什么外卖网站开发方案
  • 免费php网站空间广州安全教育平台