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.出现一个空白的标签

同上

相关推荐
一入JAVA毁终身15 小时前
处理Lombok的一个小BUG
java·开发语言·bug
SeaTunnel1 天前
SeaTunnel 社区月报(5-6 月):全新功能上线、Bug 大扫除、Merge 之星是谁?
大数据·开源·bug·数据集成·seatunnel
紫璨月1 天前
nginx反向代理的bug
运维·nginx·bug
从后端到QT1 天前
SRS流媒体服务器之本地测试rtc推流bug
bug·实时音视频
Java知识库12 天前
MySQL RC隔离级别惊现间隙锁:是bug吗?
数据库·mysql·bug
安卓机器12 天前
rom定制系列------红米note11 5G版 MTK芯片强解bl锁修复bug 官方系统 面具root批量线刷版
5g·bug
剽悍一小兔12 天前
一个小BUG引发的对Mybatis-Plus的模糊查询的思考
bug·mybatis
Gazer_S13 天前
【前端隐蔽 Bug 深度剖析:SVG 组件复用中的 ID 冲突陷阱】
前端·bug
电手15 天前
Win11用户尽快删除更新!微软6月又推Bug
microsoft·bug
穆易青15 天前
2025.06.17【BUG】|多样品VCF文件合并技巧及注意事项(以bcftools为例)
bug