码迷,mamicode.com
首页 > 其他好文 > 详细

vuex : 用vuex控制侧栏点亮状态

时间:2019-02-13 22:29:29      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:push   data   padding   source   route   r.js   inner   name   console   

上代码。

 

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/>‘
})

以上。

 

vuex : 用vuex控制侧栏点亮状态

标签:push   data   padding   source   route   r.js   inner   name   console   

原文地址:https://www.cnblogs.com/foxcharon/p/10371983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!