$state.transitionto不刷新数据问题解决方法

本文介绍如何在前端应用中配置路由缓存为禁用状态,通过设置cache参数为'false'来实现页面不被缓存。
 .state('test', { 
      url: '/test',

     cache:'false', 

     templateUrl: 'templates/test.html', 

      controller: 'testCtrl' 
    }) 

添加上cache:'false'这个参数就行。
<template> <div id="tags-view-container" class="tags-view-container"> <scroll-pane ref="scrollPane" class="tags-view-wrapper" @scroll="handleScroll"> <router-link v-for="tag in visitedViews" ref="tag" :key="tag.path" :class="isActive(tag)?'active':''" :to="{ path: tag.path, query: tag.query, fullPath: tag.fullPath }" tag="span" class="tags-view-item" :style="activeStyle(tag)" @click.middle.native="!isAffix(tag)?closeSelectedTag(tag):''" @contextmenu.prevent.native="openMenu(tag,$event)" > {{ tag.title }} <span v-if="!isAffix(tag)" class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" /> </router-link> </scroll-pane> <ul v-show="visible" :style="{left:left+'px',top:top+'px'}" class="contextmenu"> <li @click="refreshSelectedTag(selectedTag)"><i class="el-icon-refresh-right"></i> 刷新页面</li> <li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)"><i class="el-icon-close"></i> 关闭当前</li> <li @click="closeOthersTags"><i class="el-icon-circle-close"></i> 关闭其他</li> <li v-if="!isFirstView()" @click="closeLeftTags"><i class="el-icon-back"></i> 关闭左侧</li> <li v-if="!isLastView()" @click="closeRightTags"><i class="el-icon-right"></i> 关闭右侧</li> <li @click="closeAllTags(selectedTag)"><i class="el-icon-circle-close"></i> 全部关闭</li> </ul> </div> </template> <script> import ScrollPane from './ScrollPane' import path from 'path' export default { components: { ScrollPane }, data() { return { visible: false, top: 0, left: 0, selectedTag: {}, affixTags: [] } }, computed: { visitedViews() { return this.$store.state.tagsView.visitedViews }, routes() { return this.$store.state.permission.routes }, theme() { return this.$store.state.settings.theme; } }, watch: { $route() { this.addTags() this.moveToCurrentTag() }, visible(value) { if (value) { document.body.addEventListener('click', this.closeMenu) } else { document.body.removeEventListener('click', this.closeMenu) } } }, mounted() { this.initTags() this.addTags() }, methods: { isActive(route) { return route.path === this.$route.path }, activeStyle(tag) { if (!this.isActive(tag)) return {}; return { "background-color": this.theme, "border-color": this.theme }; }, isAffix(tag) { return tag.meta && tag.meta.affix }, isFirstView() { try { return this.selectedTag.fullPath === '/index' || this.selectedTag.fullPath === this.visitedViews[1].fullPath } catch (err) { return false } }, isLastView() { try { return this.selectedTag.fullPath === this.visitedViews[this.visitedViews.length - 1].fullPath } catch (err) { return false } }, filterAffixTags(routes, basePath = '/') { let tags = [] routes.forEach(route => { if (route.meta && route.meta.affix) { const tagPath = path.resolve(basePath, route.path) tags.push({ fullPath: tagPath, path: tagPath, name: route.name, meta: { ...route.meta } }) } if (route.children) { const tempTags = this.filterAffixTags(route.children, route.path) if (tempTags.length >= 1) { tags = [...tags, ...tempTags] } } }) return tags }, initTags() { const affixTags = this.affixTags = this.filterAffixTags(this.routes) for (const tag of affixTags) { // Must have tag name if (tag.name) { this.$store.dispatch('tagsView/addVisitedView', tag) } } }, addTags() { const { name } = this.$route if (name) { this.$store.dispatch('tagsView/addView', this.$route) } }, moveToCurrentTag() { const tags = this.$refs.tag this.$nextTick(() => { for (const tag of tags) { if (tag.to.path === this.$route.path) { this.$refs.scrollPane.moveToTarget(tag) // when query is different then update if (tag.to.fullPath !== this.$route.fullPath) { this.$store.dispatch('tagsView/updateVisitedView', this.$route) } break } } }) }, refreshSelectedTag(view) { this.$tab.refreshPage(view); if (this.$route.meta.link) { this.$store.dispatch('tagsView/delIframeView', this.$route) } }, closeSelectedTag(view) { this.$tab.closePage(view).then(({ visitedViews }) => { if (this.isActive(view)) { this.toLastView(visitedViews, view) } }) }, closeRightTags() { this.$tab.closeRightPage(this.selectedTag).then(visitedViews => { if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { this.toLastView(visitedViews) } }) }, closeLeftTags() { this.$tab.closeLeftPage(this.selectedTag).then(visitedViews => { if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { this.toLastView(visitedViews) } }) }, closeOthersTags() { this.$router.push(this.selectedTag.fullPath).catch(()=>{}); this.$tab.closeOtherPage(this.selectedTag).then(() => { this.moveToCurrentTag() }) }, closeAllTags(view) { this.$tab.closeAllPage().then(({ visitedViews }) => { if (this.affixTags.some(tag => tag.path === this.$route.path)) { return } this.toLastView(visitedViews, view) }) }, toLastView(visitedViews, view) { const latestView = visitedViews.slice(-1)[0] if (latestView) { this.$router.push(latestView.fullPath) } else { // now the default is to redirect to the home page if there is no tags-view, // you can adjust it according to your needs. if (view.name === 'Dashboard') { // to reload home page this.$router.replace({ path: '/redirect' + view.fullPath }) } else { this.$router.push('/') } } }, openMenu(tag, e) { const menuMinWidth = 105 const offsetLeft = this.$el.getBoundingClientRect().left // container margin left const offsetWidth = this.$el.offsetWidth // container width const maxLeft = offsetWidth - menuMinWidth // left boundary const left = e.clientX - offsetLeft + 15 // 15: margin right if (left > maxLeft) { this.left = maxLeft } else { this.left = left } this.top = e.clientY this.visible = true this.selectedTag = tag }, closeMenu() { this.visible = false }, handleScroll() { this.closeMenu() } } } </script> <style lang="scss" scoped> .tags-view-container { height: 34px; width: 100%; background: #fff; border-bottom: 1px solid #d8dce5; box-shadow: 0 1px 3px 0 rgba(0, 0, 0, .12), 0 0 3px 0 rgba(0, 0, 0, .04); .tags-view-wrapper { .tags-view-item { display: inline-block; position: relative; cursor: pointer; height: 26px; line-height: 26px; border: 1px solid #d8dce5; color: #495060; background: #fff; padding: 0 8px; font-size: 12px; margin-left: 5px; margin-top: 4px; &:first-of-type { margin-left: 15px; } &:last-of-type { margin-right: 15px; } &.active { background-color: #42b983; color: #fff; border-color: #42b983; &::before { content: ''; background: #fff; display: inline-block; width: 8px; height: 8px; border-radius: 50%; position: relative; margin-right: 2px; } } } } .contextmenu { margin: 0; background: #fff; z-index: 3000; position: absolute; list-style-type: none; padding: 5px 0; border-radius: 4px; font-size: 12px; font-weight: 400; color: #333; box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, .3); li { margin: 0; padding: 7px 16px; cursor: pointer; &:hover { background: #eee; } } } } </style> <style lang="scss"> //reset element css of el-icon-close .tags-view-wrapper { .tags-view-item { .el-icon-close { width: 16px; height: 16px; vertical-align: 2px; border-radius: 50%; text-align: center; transition: all .3s cubic-bezier(.645, .045, .355, 1); transform-origin: 100% 50%; &:before { transform: scale(.6); display: inline-block; vertical-align: -3px; } &:hover { background-color: #b4bccc; color: #fff; } } } } </style> 切换标签页面得时候 怎么实现页面更新 vue2
最新发布
10-28
<template> <div class="navbar"> <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> <breadcrumb v-if="!topNav" id="breadcrumb-container" class="breadcrumb-container" /> <top-nav v-if="topNav" id="topmenu-container" class="topmenu-container" /> <div class="right-menu"> <template v-if="device!=='mobile'"> <search id="header-search" class="right-menu-item" /> <!-- <el-tooltip content="源码地址" effect="dark" placement="bottom"> <ruo-yi-git id="qiya-git" class="right-menu-item hover-effect" /> </el-tooltip> --> <!-- <el-tooltip content="文档地址" effect="dark" placement="bottom"> <ruo-yi-doc id="qiya-doc" class="right-menu-item hover-effect" /> </el-tooltip> --> <screenfull id="screenfull" class="right-menu-item hover-effect" /> <el-tooltip content="布局大小" effect="dark" placement="bottom"> <size-select id="size-select" class="right-menu-item hover-effect" /> </el-tooltip> </template> <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="hover"> <div class="avatar-wrapper"> <img :src="avatar" class="user-avatar"> <span class="user-nickname"> {{ nickName }} </span> </div> <el-dropdown-menu slot="dropdown"> <router-link to="/user/profile"> <el-dropdown-item>个人中心</el-dropdown-item> </router-link> <el-dropdown-item divided @click.native="logout"> <span>退出登录</span> </el-dropdown-item> </el-dropdown-menu> </el-dropdown> <div class="right-menu-item hover-effect setting" @click="setLayout" v-if="setting"> <svg-icon icon-class="more-up" /> </div> </div> </div> </template> <script> import { mapGetters } from 'vuex' import Breadcrumb from '@/components/Breadcrumb' import TopNav from '@/components/TopNav' import Hamburger from '@/components/Hamburger' import Screenfull from '@/components/Screenfull' import SizeSelect from '@/components/SizeSelect' import Search from '@/components/HeaderSearch' import QiYaGit from '@/components/QiYa/Git' import QiYaDoc from '@/components/QiYa/Doc' export default { emits: ['setLayout'], components: { Breadcrumb, TopNav, Hamburger, Screenfull, SizeSelect, Search, QiYaGit, QiYaDoc }, computed: { ...mapGetters([ 'sidebar', 'avatar', 'device', 'nickName' ]), setting: { get() { return this.$store.state.settings.showSettings } }, topNav: { get() { return this.$store.state.settings.topNav } } }, methods: { toggleSideBar() { this.$store.dispatch('app/toggleSideBar') }, setLayout(event) { this.$emit('setLayout') }, logout() { this.$confirm('确定注销并退出系统吗?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(async () => { try { // 1. 显示加载状态 const loadingInstance = this.$loading({ fullscreen: true }); // 2. 执行退出操作 await this.$store.dispatch('LogOut'); // 3. 取消所有pending请求 if (typeof this.$http.cancelAllRequests === 'function') { this.$http.cancelAllRequests('Operation canceled by logout'); } // 4. 使用Vue Router导航代替location.href await this.$router.push({ path: '/login', query: { logout: 'success' } }); // 5. 强制刷新页面确保完全重置 setTimeout(() => { window.location.reload(); }, 100); } catch (error) { console.error('退出失败:', error); } finally { this.$nextTick(() => { this.$loading().close(); }); } }).catch(() => {}); } } } </script> <style lang="scss" scoped> .navbar { height: 50px; overflow: hidden; position: relative; background: #fff; box-shadow: 0 1px 4px rgba(0,21,41,.08); .hamburger-container { line-height: 46px; height: 100%; float: left; cursor: pointer; transition: background .3s; -webkit-tap-highlight-color:transparent; &:hover { background: rgba(0, 0, 0, .025) } } .breadcrumb-container { float: left; } .topmenu-container { position: absolute; left: 50px; } .errLog-container { display: inline-block; vertical-align: top; } .right-menu { float: right; height: 100%; line-height: 50px; &:focus { outline: none; } .right-menu-item { display: inline-block; padding: 0 8px; height: 100%; font-size: 18px; color: #5a5e66; vertical-align: text-bottom; &.hover-effect { cursor: pointer; transition: background .3s; &:hover { background: rgba(0, 0, 0, .025) } } } .avatar-container { margin-right: 0px; padding-right: 0px; .avatar-wrapper { margin-top: 10px; position: relative; .user-avatar { cursor: pointer; width: 30px; height: 30px; border-radius: 50%; } .user-nickname{ position: relative; bottom: 10px; font-size: 14px; font-weight: bold; } .el-icon-caret-bottom { cursor: pointer; position: absolute; right: -20px; top: 25px; font-size: 12px; } } } } } </style> 为什么点击退出登录后没有返回到登录页面,而是要刷新后才能显示登录页面,退出登录后立马重新登录会加载很久同事报错:errAxiosError: timeout of 10000ms exceeded
08-25
这是我的SidebarItem代码,<template> <div v-if="!item.hidden"> <template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow"> <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path, onlyOneChild.query)"> <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}"> <item :icon="onlyOneChild.meta.icon||(item.meta&&item.meta.icon)" :title="onlyOneChild.meta.title" /> </el-menu-item> </app-link> </template> <el-submenu v-else ref="subMenu" :index="resolvePath(item.path)" popper-append-to-body> <template slot="title"> <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" /> </template> <sidebar-item v-for="(child, index) in item.children" :key="child.path + index" :is-nest="true" :item="child" :base-path="resolvePath(child.path)" class="nest-menu" /> </el-submenu> </div> </template> <script> import path from 'path' import { isExternal } from '@/utils/validate' import Item from './Item' import AppLink from './Link' import FixiOSBug from './FixiOSBug' export default { name: 'SidebarItem', components: { Item, AppLink }, mixins: [FixiOSBug], props: { // route object item: { type: Object, required: true }, isNest: { type: Boolean, default: false }, basePath: { type: String, default: '' } }, data() { this.onlyOneChild = null return {} }, methods: { hasOneShowingChild(children = [], parent) { if (!children) { children = []; } const showingChildren = children.filter(item => { if (item.hidden) { return false } else { // Temp set(will be used if only has one showing child) this.onlyOneChild = item return true } }) // When there is only one child router, the child router is displayed by default if (showingChildren.length === 1) { return true } // Show parent if there are no child router to display if (showingChildren.length === 0) { this.onlyOneChild = { ... parent, path: '', noShowingChildren: true } return true } return false }, resolvePath(routePath, routeQuery) { if (isExternal(routePath)) { return routePath } if (isExternal(this.basePath)) { return this.basePath } if (routeQuery) { let query = JSON.parse(routeQuery); return { path: path.resolve(this.basePath, routePath), query: query } } return path.resolve(this.basePath, routePath) } } } </script> 这是我的index代码,<template> <div :class="{'has-logo':showLogo}" :style="{ backgroundColor: settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackground }"> <el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper"> <el-menu :default-active="activeMenu" :collapse="isCollapse" :background-color="settings.sideTheme === 'theme-dark' ? variables.menuColorActive : variables.menuLightBackground" :text-color="settings.sideTheme === 'theme-dark' ? variables.menuLightColor : variables.menuBackground" :unique-opened="true" :active-text-color="settings.theme" :collapse-transition="false" mode="vertical" @select="handleSelect" :default-openeds="openedMenus" > <sidebar-item v-for="(route, index) in sidebarRouters" :key="route.path + index" :item="route" :base-path="route.path" /> </el-menu> </el-scrollbar> </div> </template> <script> import { mapGetters, mapState, mapActions } from "vuex"; import Logo from "./Logo"; import SidebarItem from "./SidebarItem"; import variables from "@/assets/styles/variables.scss"; export default { components: { SidebarItem, Logo }, data(){ return{ openedMenus: [] // 新增状态用于存储展开的菜单 } }, // 在mounted中添加滚动监听 mounted() { const menuContainer = this.$refs.sidebar.$el.querySelector('.el-menu'); menuContainer.addEventListener('scroll', this.saveScrollPosition); }, // 在beforeDestroy中移除监听 beforeDestroy() { const menuContainer = this.$refs.sidebar.$el.querySelector('.el-menu'); menuContainer.removeEventListener('scroll', this.saveScrollPosition); }, computed: { ...mapState(["settings", "app"]), ...mapGetters(["sidebarRouters", "sidebar"]), activeMenu() { const route = this.$route; const { meta, path } = route; if (meta.activeMenu) { return meta.activeMenu; } return path; }, showLogo() { return this.$store.state.settings.sidebarLogo; }, variables() { return variables; }, isCollapse() { // 如果 disableMenuCollapse 为 true,则菜单收缩 // return this.app.disableMenuCollapse ? false : !this.sidebar.opened; return !this.sidebar.opened } }, watch: { $route: { immediate: true, handler(route) { // 保持父级菜单展开状态 const matched = route.matched.filter(item => item.meta && item.meta.title) const parents = matched.map(item => item.path) this.openedMenus = parents } } }, methods: { handleSelect(index, indexPath) { // 更新展开菜单状态 this.openedMenus = indexPath.slice(0, -1) }, saveScrollPosition(e) { this.$store.commit('SET_MENU_SCROLL', e.target.scrollTop); } } }; </script> 请结合代码帮我看一下具体怎么修改
06-05
<body> <div class="conter"> </div> </body><script>let dataJsons = []; let dataJsonsErr =[ { "cardid": "0422AA12361E90", "building": "B栋", "floor": "1F", "area": "电气室", "project": "风扇1", "status":"OK", "msg":"", "checkTime":"2025.6.27-15:41:22" }, { "cardid": "0423AA12361E90", "building": "B栋", "floor": "1F", "area": "电气室", "project": "风扇2", "status":"OK", "msg":"", "checkTime":"2025.6.25-17:21:32" }, { "cardid": "0424AA12361E90", "building": "B栋", "floor": "2F", "area": "电气室", "project": "风扇3", "status":"NG", "msg":"异常报错2", "checkTime":"2025.6.24-10:11:08" },{ "cardid": "0425AA12361E90", "building": "B栋", "floor": "1F", "area": "电气室", "project": "风扇13", "status":"OK", "msg":"", "checkTime":"2025.6.25-17:21:32" }, { "cardid": "0426AA12361E90", "building": "B栋", "floor": "2F", "area": "电气室", "project": "风扇12", "status":"NG", "msg":"异常报错2", "checkTime":"2025.6.24-10:11:08" }, { "cardid": "0424AA12361E90", "building": "B栋", "floor": "2F", "area": "电气室", "project": "风扇3", "status":"NG", "msg":"异常报错2", "checkTime":"2025.6.24-10:11:08" }]; $(".conter").append( '<div class="InputDatas">'+ '<input class="AllDatas" id="searchInput" type="text" placeholder="输入搜索内容" value="" />'+ '<span id="resultCount">'+'</span>'+ '</div>'+ '<div class="u4Scoll" id="inputs-Scoll">'+ '<div class="BDALL">'+ '</div>'+ '</div> '+ '<button class="BtnTR">'+'提交任务'+'</button>'); $(".BtnTR").click(function(){ //其他代码 }) $.each(dataJsonsErr,function(index, item){ if(item.status == "OK"){ $(".BDALL").append( '<div class="BDSS">'+ '<div class="BDS_state" data-Text="正常">'+'</div>'+ '<div class="BDS_stateA">'+ '<P class="BDS_ID">'+'ID:'+ item.cardid +'</P>'+ '<P class="BDS_time">'+'时间:'+item.checkTime+'</P>'+ '<div class="BDS_stateWhy">'+ '<P class="BDS_decser">'+'备注:'+'</P>'+ '<p class="BDS_decserTexts" >'+ "无" +'</P>'+ '</div>'+ '</div>'+ '</div>'); }else if(item.status == "NG"){ $(".BDALL").append( '<div class="BDSS">'+ '<div class="BDS_states" data-Text="异常">'+'</div>'+ '<div class="BDS_stateA">'+ '<P class="BDS_ID">'+'ID:'+ item.cardid +'</P>'+ '<P class="BDS_time">'+'时间:'+item.checkTime+'</P>'+ '<div class="BDS_stateWhy">'+ '<P class="BDS_decser">'+'备注:'+'</P>'+ '<p class="BDS_decserTexts" >'+ item.msg +'</P>'+ '</div>'+ '</div>'+ '</div>'); } }); //关键词搜索 // 实时搜索功能 $('#searchInput').on('input', function() { const keyword = $(this).val().trim(); const $pTags = $('.BDSS p'); let matchCount = 0; let firstMatch = null; // 清除之前的高亮 $pTags.removeClass('highlight'); $pTags.find('span.highlight').each(function() { $(this).replaceWith($(this).text()); }); if (keyword.length > 0) { // 遍历所有p标签 $pTags.each(function() { const $p = $(this); const text = $p.text(); const regex = new RegExp(keyword, 'gi'); if (regex.test(text)) { matchCount++; // 标记第一个匹配项 if (!firstMatch) firstMatch = this; // 高亮显示关键词 const highlighted = text.replace(regex, match => `<span class="highlight">${match}</span>` ); $p.html(highlighted); } }); // 显示匹配数量 $('#resultCount').text(`找到 ${matchCount} 个结果`); // 滚动到第一个匹配项 if (firstMatch) { $('.BDALL').animate({ scrollTop: $(firstMatch).offset().top - $('.BDALL').offset().top + $('.BDALL').scrollTop() - 20 }, 500); } } else { $('#resultCount').text(''); // 恢复原始文本 $pTags.each(function() { $(this).text($(this).text()); }); } });</script>,想实现u4Scoll根据BtnTR所在的位置高度作为u4Scoll的盒子高度,BDALL里面新增的数据一旦超过u4Scoll盒子高度就开始overflow-y触发。由于在同屏幕上BtnTR所在的位置高度也一样,所以得让u4Scoll盒子的高度跟BtnTR所在的位置高度同步才行。怎么实现这个功能(这个代码实现地方是同类型的android手机的移动端的屏幕)
08-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值