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

同上

相关推荐
kunkun1011 天前
关于软件测试中的bug
python·bug·压力测试
用键盘当武器的秋刀鱼2 天前
springboot-bug
java·spring boot·bug
星辰&与海2 天前
报错 watcgdog: BUG; soft lockup -CPU#0 stuck for 26s! [swapper/0:1]
bug
无人等人3 天前
CyberRT(apollo) 定时器模块简述及bug分析
bug
fengdongnan3 天前
bug小记
bug
天才测试猿3 天前
解决Selenium元素拖拽不生效Bug
linux·自动化测试·软件测试·python·selenium·测试工具·bug
四角小裤儿儿3 天前
软件测试(三)——Bug篇
功能测试·面试·单元测试·bug
开发者工具分享3 天前
测试是如何跟进和管理 bug
bug
Htht1116 天前
【Linux】之【Bug】VMware 虚拟机开机 一直卡在黑屏左上角下划线闪烁界面
linux·运维·bug
你的坚定7 天前
记Android12上一个原生bug引起的system_server crash
bug