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

    以上。

  • 相关阅读:
    函数的调用过程
    Android基础-弹出式菜单
    Android基础-上下文菜单(Content_Menu)
    Adnroid基础-选项菜单(OptionMenu)
    Android基础-UI界面(项目实战 点菜界面) 1.EditText 2.SeekBar 3.CheckBox 4.ToggleButton 5.RadioGroup 6.Button 7.TextView 8.ImageView
    Android基础-进度条(SeekBar)
    Android基础-开关按钮(ToggleButton)
    Android基础-单选框(RadioButton)
    显示应用名称
    在Xcode中使用pch文件
  • 原文地址:https://www.cnblogs.com/foxcharon/p/10371983.html
Copyright © 2011-2022 走看看