Vue Element sub navigation route is selected issues

  • First, that problem encountered
    • 1. Go to the nested routing, navigation current parent can not be highlighted
    • When the page refreshes navigation reset problem
    • 3. Refresh the page in a nested navigation routes can also cause problems reset

  • Next is the solution:
    ElementUI there are attributes default-active (menu of the currently active index)
<el-menu :default-active="activeIndex" @select="handleSelect" router></el-menu>

data () {
    return {
        activeIndex: '/'
    }
},
watch: {
    '$route' () {
        this.handleSelect(this.activeIndex)
    }
},
mounted () {
    this.activeIndex = this.$route.matched[0].path || '/'
},
methods: {
    handleSelect (index) {
        this.activeIndex = index
    }
},

This OK

## END

Under that help small partners like the point of a support ~

I feel a small partner to help point a praise ~

Guess you like

Origin www.cnblogs.com/zheroXH/p/11613079.html