11.动态标签页的一些优化和bug的解决

动态标签页有一些需要优化的地方和bug

1.解决删除标签页,内容不会替换为上一个标签页

复制代码
    removeTab(targetName) {
      if ( targetName === 'Index') {
        console.log("首页不能被删除")
        return;
      }
      let tabs = this.editableTabs;
      let activeName = this.editableTabsValue;
      if (activeName === targetName) {
        tabs.forEach((tab, index) => {
          if (tab.name === targetName) {
            let nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              activeName = nextTab.name;
            }
//在删除方法里加上这一个路由的切换,当删除一个标签,就会路由到前一个标签
            this.$router.push({name: nextTab.name});
          }
        });
      }

      this.editableTabsValue = activeName;
      this.editableTabs = tabs.filter(tab => tab.name !== targetName);
    },
    tabClick(target) {
      this.$router.push({name: target.name});
    }
  }

2.用户使用网址进入,没有标签

当用户使用网址进入时,可以看到页面,但是没有对应的标签

因为我这里是一个嵌套页面,归根结底还是app.vue

所以使用监听器

复制代码
export default {
  name: "App",
  watch:{
    $route(to,from){
      if (to.path != '/login' && to.path != '/sys/Index' && to.path != '/'){
        console.log("to")
        console.log(to);
        let obj = {
          name: to.name,
          title: to.meta.title,
        }
        this.$store.commit('addTab', obj);
      }
    }
  }

3.用户退出,标签页不会被清空

调用方法将其清空

复制代码
        REMOVE_TOKEN: (state) => {
            state.token = ''
            localStorage.removeItem("token")
            state.menuList = [];
            state.authoritys = [];
            state.validation = false;
            state.editableTabsValue = 'Index';
            state.editableTabs = [{
                title: '首页',
                name: 'Index'
            }];
        }

4.首页不能被删除

复制代码
加一个判断   
 removeTab(targetName) {
      if ( targetName === 'Index') {
        console.log("首页不能被删除")
        return;
      }
      let tabs = this.editableTabs;
      let activeName = this.editableTabsValue;
      if (activeName === targetName) {
        tabs.forEach((tab, index) => {
          if (tab.name === targetName) {
            let nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              activeName = nextTab.name;
            }
            this.$router.push({name: nextTab.name});
          }
        });
      }

5.出现两个首页标签

这是因为监听器没有判断目标网页是不是首页

复制代码
  watch:{
    $route(to,from){
      if (to.path != '/login' && to.path != '/sys/Index' && to.path != '/'){
        console.log("to")
        console.log(to);
        let obj = {
          name: to.name,
          title: to.meta.title,
        }
        this.$store.commit('addTab', obj);
      }
    }
  }

6.出现一个空白的标签

同上

相关推荐
chao_7891 小时前
针对“仅某个地区出现Bug”的原因分析与解决方案
测试用例·bug
帅帅哥的兜兜1 小时前
Bug问题
bug
养意1 小时前
git提交代码和解决冲突修复bug
git·bug
东方不败之鸭梨的测试笔记16 小时前
20250605车充安服务器受木马攻击导致服务不可用
bug
Htht11117 小时前
【Qt】之【Get√】【Bug】通过值捕获(或 const 引用捕获)传进 lambda,会默认复制成 const
数据库·bug
前端发现20 小时前
如何用 pnpm patch 给 element-plus 打补丁修复线上 bug(以 2.4.4 修复 PR#15197 为例)
bug
可乐鸡翅好好吃1 天前
通过BUG(prvIdleTask、pxTasksWaitingTerminatio不断跳转问题)了解空闲函数(prvIdleTask)和TCB
c语言·stm32·单片机·嵌入式硬件·bug·keil
神膘护体小月半2 天前
bug 记录 - 使用 el-dialog 的 before-close 的坑
前端·javascript·bug
顽强d石头2 天前
bug:undefined is not iterable (cannot read property Symbol(Symbol.iterator))
前端·bug
阿松のblog3 天前
opencv使用经典bug
人工智能·opencv·bug