feat: add vuex state managment
This commit is contained in:
Generated
+161
-11598
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -30,10 +30,11 @@
|
|||||||
"@coreui/coreui": "^3.0.0-beta.4",
|
"@coreui/coreui": "^3.0.0-beta.4",
|
||||||
"@coreui/icons": "^1.0.0",
|
"@coreui/icons": "^1.0.0",
|
||||||
"@coreui/utils": "^1.2.2",
|
"@coreui/utils": "^1.2.2",
|
||||||
"@coreui/vue": "^3.0.0-beta.10",
|
"@coreui/vue": "../coreui-vue",
|
||||||
"@coreui/vue-chartjs": "^1.0.3",
|
"@coreui/vue-chartjs": "^1.0.3",
|
||||||
"vue": "^2.6.11",
|
"vue": "^2.6.11",
|
||||||
"vue-router": "^3.1.5"
|
"vue-router": "^3.1.5",
|
||||||
|
"vuex": "^3.1.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vue/cli-plugin-babel": "^4.1.2",
|
"@vue/cli-plugin-babel": "^4.1.2",
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
<CToggler
|
<CToggler
|
||||||
in-header
|
in-header
|
||||||
class="ml-3 d-lg-none"
|
class="ml-3 d-lg-none"
|
||||||
v-c-emit-root-event:toggle-sidebar-mobile
|
@click="$store.commit('toggleSidebarMobile')"
|
||||||
/>
|
/>
|
||||||
<CToggler
|
<CToggler
|
||||||
in-header
|
in-header
|
||||||
class="ml-3 d-md-down-none"
|
class="ml-3 d-md-down-none"
|
||||||
v-c-emit-root-event:toggle-sidebar
|
@click="$store.commit('toggleSidebarDesktop')"
|
||||||
/>
|
/>
|
||||||
<CHeaderBrand class="mx-auto d-lg-none" to="/">
|
<CHeaderBrand class="mx-auto d-lg-none" to="/">
|
||||||
<CIcon name="logo" height="48" alt="Logo"/>
|
<CIcon name="logo" height="48" alt="Logo"/>
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
<CSidebar
|
<CSidebar
|
||||||
fixed
|
fixed
|
||||||
:minimize="minimize"
|
:minimize="minimize"
|
||||||
:show.sync="show"
|
:show="show"
|
||||||
|
@update:show="(value) => $store.commit('set', ['sidebarShow', value])"
|
||||||
>
|
>
|
||||||
<CSidebarBrand class="d-md-down-none" to="/">
|
<CSidebarBrand class="d-md-down-none" to="/">
|
||||||
<CIcon
|
<CIcon
|
||||||
@@ -14,10 +15,10 @@
|
|||||||
/>
|
/>
|
||||||
</CSidebarBrand>
|
</CSidebarBrand>
|
||||||
|
|
||||||
<CRenderFunction flat :content-to-render="nav"/>
|
<CRenderFunction flat :content-to-render="$options.nav"/>
|
||||||
<CSidebarMinimizer
|
<CSidebarMinimizer
|
||||||
class="d-md-down-none"
|
class="d-md-down-none"
|
||||||
@click.native="minimize = !minimize"
|
@click.native="$store.commit('set', ['sidebarMinimize', !minimize])"
|
||||||
/>
|
/>
|
||||||
</CSidebar>
|
</CSidebar>
|
||||||
</template>
|
</template>
|
||||||
@@ -27,22 +28,14 @@ import nav from './_nav'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'TheSidebar',
|
name: 'TheSidebar',
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
minimize: false,
|
|
||||||
nav,
|
nav,
|
||||||
show: 'responsive'
|
computed: {
|
||||||
}
|
show () {
|
||||||
|
return this.$store.state.sidebarShow
|
||||||
},
|
},
|
||||||
mounted () {
|
minimize () {
|
||||||
this.$root.$on('toggle-sidebar', () => {
|
return this.$store.state.sidebarMinimize
|
||||||
const sidebarOpened = this.show === true || this.show === 'responsive'
|
}
|
||||||
this.show = sidebarOpened ? false : 'responsive'
|
|
||||||
})
|
|
||||||
this.$root.$on('toggle-sidebar-mobile', () => {
|
|
||||||
const sidebarClosed = this.show === 'responsive' || this.show === false
|
|
||||||
this.show = sidebarClosed ? true : 'responsive'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import App from './App'
|
|||||||
import router from './router'
|
import router from './router'
|
||||||
import CoreuiVue from '@coreui/vue/src'
|
import CoreuiVue from '@coreui/vue/src'
|
||||||
import { iconsSet as icons } from './assets/icons/icons.js'
|
import { iconsSet as icons } from './assets/icons/icons.js'
|
||||||
|
import store from './store'
|
||||||
|
|
||||||
Vue.config.performance = true
|
Vue.config.performance = true
|
||||||
Vue.use(CoreuiVue)
|
Vue.use(CoreuiVue)
|
||||||
@@ -11,6 +12,7 @@ Vue.use(CoreuiVue)
|
|||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
router,
|
router,
|
||||||
|
store,
|
||||||
icons,
|
icons,
|
||||||
template: '<App/>',
|
template: '<App/>',
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
+6
-5
@@ -3,17 +3,18 @@ import Vuex from 'vuex'
|
|||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
showSidebar: 'responsive'
|
sidebarShow: 'responsive',
|
||||||
|
sidebarMinimize: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const mutations = {
|
const mutations = {
|
||||||
toggleSidebarDesktop (state) {
|
toggleSidebarDesktop (state) {
|
||||||
const sidebarOpened = [true, 'responsive'].includes(state.showSidebar)
|
const sidebarOpened = [true, 'responsive'].includes(state.sidebarShow)
|
||||||
state.showSidebar = sidebarOpened ? false : 'responsive'
|
state.sidebarShow = sidebarOpened ? false : 'responsive'
|
||||||
},
|
},
|
||||||
toggleSidebarMobile (state) {
|
toggleSidebarMobile (state) {
|
||||||
const sidebarClosed = [false, 'responsive'].includes(state.showSidebar)
|
const sidebarClosed = [false, 'responsive'].includes(state.sidebarShow)
|
||||||
state.showSidebar = sidebarClosed ? true : 'responsive'
|
state.sidebarShow = sidebarClosed ? true : 'responsive'
|
||||||
},
|
},
|
||||||
set (state, [variable, value]) {
|
set (state, [variable, value]) {
|
||||||
state[variable] = value
|
state[variable] = value
|
||||||
|
|||||||
Reference in New Issue
Block a user