zoukankan      html  css  js  c++  java
  • vuex : 用vuex控制侧栏点亮状态

    上代码。

    xxx.vue

    <template>
        <div id="xxx">
            <div class="layout">
                <Layout>
                    <Sider breakpoint="md" collapsible :collapsed-width="78" :width="106">
                        <Menu :active-name="getActiceName" theme="dark" width="auto" :style="{padding:'10px 0 0'}">
                            <MenuItem name="1-1" @click.native="jump(1)">                            
                                <span>来源字典</span>
                            </MenuItem>
                            <MenuItem name="1-2" @click.native="jump(2)">                            
                                <span>权限字典</span>
                            </MenuItem>
                        </Menu>
                        <div slot="trigger"></div>
                    </Sider>
                    <Layout>
                        <Content :style="{margin: '0', background: '#212121', minHeight: content_height}">
                            <router-view></router-view>
                        </Content>
                    </Layout>
                </Layout>
            </div>
        </div>
    </template>
    
    <script>
    export default {
        name: "xxx",
        data() {
            return {
                // activeNameString:'1-1',
                routerIndex:1,
                header_height:70,
                content_height:220 + 'px'
            }
        },
        methods:{
            jump(index){
                if (index === 1) {
                    this.$router.push('/backHome/dictionary/source')
                } else if (index === 2) {
                    this.$router.push('/backHome/dictionary/authority')
                } else if (index === 3) {
                    this.$router.push('/backHome/dictionary/account')
                }
            }
        },
        computed:{
            getActiceName(){            
                return this.$store.state.activeNameString
            }
        },
        components: {
            
        },
        created() {
            console.log(this.$store.state.activeNameString)
        },
        mounted(){
            this.content_height = window.innerHeight - this.header_height + 'px'
        }
    };
    </script>

    store.js

    export const store = {
      state:{
        test:"hello",
        activeNameString:"1-1"
      },
      getters:{
      },
      mutations:{
        changeActiveNameFunc(state, obj){
          state.activeNameString = obj.activeNameString
        }
      },
      actions:{
        changeActiveNameFunc(context, obj){
          context.commit('changeActiveNameFunc', obj)
        }
      }
    }

    main.js

    ...
    import Vue from 'vue'
    import App from './App'
    import Vuex from 'vuex'
    // iview
    import iView from 'iview';
    Vue.use(iView);
    // vuex
    Vue.use(Vuex)
    import {router} from './router.js'
    import {store} from './store.js'
    
    const s = new Vuex.Store(store)
    ...
    const v = new Vue({
      el: '#app',
      router,
      store:s,
      components: { App },
      template: '<App/>'
    })

    以上。

  • 相关阅读:
    AspNet Core 核心 通过依赖注入(注入服务)
    AspNetCore 中使用 InentityServer4(2)
    AspNetCore中使用Ocelot之 IdentityServer4(1)
    AspNetCore+Swagger 生成Model 描述
    scp带密码拷贝文件
    redis集群之节点少于六个错误-解决
    [AWS DA Guru] Serverless compute Exam Tips
    [AWS] Lambda Invocation types
    [AWS Developer Guru] CI/CD
    [AWS] Lab: CloudFormation nested stack
  • 原文地址:https://www.cnblogs.com/foxcharon/p/10371983.html
Copyright © 2011-2022 走看看