didiyu
2019-08-09 71dd80c584a59d608e3aca6f06ade23ae12d414b
src/components/MainMenu.vue
@@ -17,12 +17,12 @@
                :class="{'show-this':menu.subShow, 'show-this-hover':menu.subShowHover}">
                <ul>
                    <li v-for="(children, sKey) in menu.childrens" :key="sKey">
                        <a
                            :href="children.url"
                        <router-link
                            :to="children.url"
                            :class="{active: children.active}"
                            @click="subClick(key, sKey)">
                            @click.native="subClick(key, sKey)">
                            {{children.txt}}
                        </a>
                        </router-link>
                    </li>
                </ul>
            </div>
@@ -47,13 +47,13 @@
                    subShowHover:false, // 是否显示对应的子导航
                    childrens: [
                        {
                            txt: '状态信息',
                            url: '#',
                            txt: '状态显示',
                            url: '/home/state',
                            active: true
                        },
                        {
                            txt: '账户信息',
                            url: '#',
                            url: '/home/account',
                            active: false
                        },
                        {
@@ -73,17 +73,17 @@
                    childrens: [
                        {
                            txt: '过程监控',
                            url: '#',
                            url: '/monitor/process',
                            active: false
                        },
                        {
                            txt: '通道选择',
                            url: '#',
                            url: '/monitor/channnel',
                            active: false
                        },
                        {
                           txt: '信息显示',
                            url: '#',
                            url: '/monitor/info',
                            active: false 
                        }
                    ] 
@@ -98,7 +98,7 @@
                    childrens: [
                        {
                            txt: '故障诊断',
                            url: '#',
                            url: '/testing/fault',
                            active: false
                        },
                        {
@@ -118,7 +118,7 @@
                    childrens: [
                        {
                            txt: '故障分析',
                            url: '#',
                            url: '/data/failure',
                            active: false
                        },
                        {
@@ -251,7 +251,31 @@
            menu.subShow = true;
            menu.active = true;
            children.active = true;
        },
        setMenuState: function(path) {
            var key = 0;
            var skey = 0;
            // 遍历menu的值
            for(var i=0; i<this.menus.length; i++) {
                var menu = this.menus[i];
                var childrens = menu.childrens;
                for(var k=0; k<childrens.length; k++){
                    var children = childrens[k];
                    if(children.url != '#' && children.url == path) {
                        key = i;
                        skey = k;
                    }
                }
            }
            this.subClick(key, skey);
        }
    },
    mounted: function() {
        var path = this.$route.path;
        var store = this.$store;
        // 根据路由设置导航状态
        this.setMenuState(store.state.path);
    }
}
</script>