1

我的目录结构是这样的:

. ├─ README.md ├─ contact.md ├─ about.md ├─ foo/ | ├─ test/ | | ├─ README.md | | ├─ three.md | | └─ four.md │ ├─ README.md │ ├─ one.md │ └─ two.md └─ bar/ ├─ README.md └─ five.md

如何更新配置以定义每个部分和文件夹的侧边栏?

4

2 回答 2

1

您可以在此处的文档中查看如何实现此目的的示例 - https://vuepress.vuejs.org/theme/default-theme-config.html#multiple-sidebars

于 2018-09-06T09:18:36.197 回答
1

你可以在这里阅读全文。

设置

$ npm install -g vue-cli
$ vue init webpack <project-name>
$ npm install --save vuex gsap

Vuex 模块

const types = {
  TOGGLE_SIDEBAR = 'TOGGLE_SIDEBAR' 
}

// initial state
const state = {
  sidebarOpen: false
}

// getters
const getters = {
  sidebarOpen: state => state.sidebarOpen
}

// actions
const actions = {
  toggleSidebar ({ commit, state }) {
    commit(types.TOGGLE_SIDEBAR)
  }
}

// mutations
const mutations = {
  [types.TOGGLE_SIDEBAR] (state) {
    state.sidebarOpen = !state.sidebarOpen
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}

店铺

import Vue from 'vue'
import Vuex from 'vuex'
import ui from './modules/ui'

Vue.use(Vuex)

const debug = process.env.NODE_ENV !== 'production'

export default new Vuex.Store({
  modules: {
    ui
  },
  strict: debug
})

您可以看到我们导入 UI 模块并将其作为模块添加到导出的 Vuex.Store 对象中。现在,我们所要做的就是将它添加到我们的 Vue 实例中。

import Vue from 'vue'
import App from './App'
import store from './store/index.js'

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  template: '<App/>',
  components: { App }
})

组件(文件)...

APP.vue

<template>
  <div id="app">
    <div :class="$style.container">

    </div>
    <sidebar/>
    <sidebar-toggle/>
  </div>
</template>

<script>
import Sidebar from '@/components/sidebar.vue'
import SidebarToggle from '@/components/sidebarToggle.vue'
export default {
  name: 'app',
  components: {
    Sidebar, SidebarToggle
  }
}
</script>

<style>
  :root{
    --accent-color: #FFCB08;
    --primary-color: #820263;
    --dark-color: #2E294E;
  }

  *{
    box-sizing: border-box;
  }
</style>

<style module>
  .container{
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 100vw;
    background-color: var(--primary-color);
  }
</style>

侧边栏工具

<template>
  <button :class="[open ? $style.active : '', $style.button]" @click="handleClick">    
    <svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
      <path d="M0 0h24v24H0z" fill="none"/>
      <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm5 11h-4v4h-2v-4H7v-2h4V7h2v4h4v2z"/>
    </svg>
  </button>
</template>

<script>
  import {TweenMax, Power4} from 'gsap'
  export default {
    name: 'sidebar-toggle',
    computed: {
      open () {
        return this.$store.state.ui.sidebarOpen
      }
    },
    methods: {
      handleClick () {
        this.$store.dispatch('toggleSidebar')
      }
    }
  }
</script>

侧边栏

<template>
  <div :class="$style.sidebar"/>
</template>

<script>
  import {TweenMax, Power4} from 'gsap'
  export default {
    name: 'sidebar',
    mounted () {
      TweenMax.set(this.$el, {
        x: this.$el.offsetWidth
      })
    },
    computed: {
      open () {
        return this.$store.state.ui.sidebarOpen
      }
    },
    watch: {
      open: function (open) {
        const dX = open ? 0 : this.$el.offsetWidth
        TweenMax.to(this.$el, 0.6, {
          x: dX,
          ease: Power4.easeOut
        })
      }
    }
  }
</script>

路线的演示结构

{//For Dropdown
"name":"Settings",
"route":undefined,
"icon":"/assets/icons/ic_settings_white_24px.svg",//"/assets/icons/ic_settings_black_24px.svg"
"children":[
    {
        "name":"Generate Code",
        "route":"settings/code"
    },
    {
        "name":"Subscription Layout",
        "route":"settings/layout"
    },
    {
        "name":"Plans",
        "route":"settings/plans"
    }
]
}

{//For Routes
    "name":"Settings",
    "route":"/settings",
    "icon":"/assets/icons/ic_settings_white_24px.svg",//"/assets/icons/ic_settings_black_24px.svg"
    "children":[]
}
于 2018-09-06T06:44:09.820 回答