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

同上

相关推荐
waves浪游10 小时前
自动化测试实战篇
测试用例·bug·测试
DarkAthena1 天前
【ORACLE】记录一些ORACLE的merge into语句的BUG
数据库·oracle·bug
猫猫头有亿点炸1 天前
大数据可能出现的bug之flume
大数据·bug·flume
PLUS_WAVE2 天前
【CUDA 编译 bug】ld: cannot find -lcudart
服务器·c++·bug·环境·编译·cuda·ld
宁酱醇2 天前
各种各样的bug合集
开发语言·笔记·python·gitlab·bug
有什么东东2 天前
山东大学软件学院创新项目实训开发日志(20)之中医知识问答自动生成对话标题bug修改
java·vue·bug·springboot
软件技术NINI2 天前
详解BUG(又名:BUG的生命周期)
bug
兮动人2 天前
Idea使用github copilot登录bug+解决方案
github·bug·intellij-idea
Macle_Chen2 天前
ios开发中xxx.debug.dylib not found
ios·bug·debug.dylib
福大大架构师每日一题2 天前
docker v28.1.1 正式发布!修复关键Bug,网络与安全性再升级
网络·docker·bug