Vue-element-admin: 如何动态修改 面包屑 和 标签栏

Created on 2 Jul 2018  ·  11Comments  ·  Source: PanJiaChen/vue-element-admin

大佬,你好。
小弟,再做一个报表系统,希望 动态修改 面包屑 和 标签栏,显示报表的名称。不知道可以实现吗
谢谢

need repro

Most helpful comment

已解决。以下是解决代码。供后人才考。
VUE

this.$route.meta.title = reportName    
this.$store.dispatch('editVisitedViews', this.$route)

tagsView.js

        EDIT_VISITED_VIEWS: (state, view) => {    
            for (var Index in state.visitedViews) {        
                console.log(state.visitedViews[Index].path)        
                if (state.visitedViews[Index].path == view.path) {       
                    state.visitedViews[Index].title = view.meta.title        
                }        
            }        
        },        
  。。。。。
       editVisitedViews({ commit, state }, view) {
            return new Promise((resolve) => {
                commit('EDIT_VISITED_VIEWS', view)
                resolve([...state.visitedViews])
            })
        },

All 11 comments

没懂你具体的需求。

需求

  1. 每当我点击查看,就打开一个新的页面
  2. 页面的 标签名称 就显示 报表的名称

疑问:

  1. 如何修改 标签 的名称
  2. 如何修改 面包屑的名称

现在默认都是读取 route meta.title的属性,要么你改这个属性,要么去改读取的function。

this.$route.meta.title = reportName
通过这种方式修改后,面包屑生效了,但是标签 没有实时生效。
望大神赐教
[img]https://image.ibb.co/euCb6d/QQ20180703_132435.jpg[/img]

1

2

打开第一个标签,显示异常
打开第二个标签,显示第一个的名字
打开第三个标签,显示第二个的名字

已解决。以下是解决代码。供后人才考。
VUE

this.$route.meta.title = reportName    
this.$store.dispatch('editVisitedViews', this.$route)

tagsView.js

        EDIT_VISITED_VIEWS: (state, view) => {    
            for (var Index in state.visitedViews) {        
                console.log(state.visitedViews[Index].path)        
                if (state.visitedViews[Index].path == view.path) {       
                    state.visitedViews[Index].title = view.meta.title        
                }        
            }        
        },        
  。。。。。
       editVisitedViews({ commit, state }, view) {
            return new Promise((resolve) => {
                commit('EDIT_VISITED_VIEWS', view)
                resolve([...state.visitedViews])
            })
        },

X-Mars大大,感谢,照你方法OK,但是切换标签的时候,面包屑不跟着改变哦,请问你有解决方案么?

sharexia

this.$route.meta.title = reportName    

这个是修改面包屑的方法,你找找切换标签的地方,加上这句试试。

这个方法连左侧的菜单项都被改了。

Was this page helpful?
0 / 5 - 0 ratings