Skip to content

feature replace vuex with pinia #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"@coreui/vue": "^4.5.0",
"@coreui/vue-chartjs": "2.0.1",
"core-js": "^3.26.1",
"pinia": "^2.0.29",
"vue": "^3.2.45",
"vue-router": "^4.1.6",
"vuex": "^4.1.0"
"vue-router": "^4.1.6"
},
"devDependencies": {
"@babel/core": "^7.20.2",
Expand Down
6 changes: 5 additions & 1 deletion src/components/AppHeader.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<CHeader position="sticky" class="mb-4">
<CContainer fluid>
<CHeaderToggler class="ps-1" @click="$store.commit('toggleSidebar')">
<CHeaderToggler class="ps-1" @click="sidebarStore.toggleSidebar">
<CIcon icon="cil-menu" size="lg" />
</CHeaderToggler>
<CHeaderBrand class="mx-auto d-lg-none" to="/">
Expand Down Expand Up @@ -48,15 +48,19 @@
import AppBreadcrumb from './AppBreadcrumb'
import AppHeaderDropdownAccnt from './AppHeaderDropdownAccnt'
import { logo } from '@/assets/brand/logo'
import useSidebarStore from '@/stores/sidebar'
export default {
name: 'AppHeader',
components: {
AppBreadcrumb,
AppHeaderDropdownAccnt,
},
setup() {
const sidebarStore = useSidebarStore()

return {
logo,
sidebarStore,
}
},
}
Expand Down
19 changes: 7 additions & 12 deletions src/components/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
position="fixed"
:unfoldable="sidebarUnfoldable"
:visible="sidebarVisible"
@visible-change="
(event) =>
$store.commit({
type: 'updateSidebarVisible',
value: event,
})
"
@visible-change="(event) => sidebarStore.updateSidebarVisible(event)"
>
<CSidebarBrand>
<CIcon
Expand All @@ -26,29 +20,30 @@
<AppSidebarNav />
<CSidebarToggler
class="d-none d-lg-flex"
@click="$store.commit('toggleUnfoldable')"
@click="sidebarStore.toggleUnfoldable"
/>
</CSidebar>
</template>

<script>
import { computed } from 'vue'
import { useStore } from 'vuex'
import { AppSidebarNav } from './AppSidebarNav'
import { logoNegative } from '@/assets/brand/logo-negative'
import { sygnet } from '@/assets/brand/sygnet'
import useSidebarStore from '@/stores/sidebar'
export default {
name: 'AppSidebar',
components: {
AppSidebarNav,
},
setup() {
const store = useStore()
const sidebarStore = useSidebarStore()
return {
logoNegative,
sygnet,
sidebarUnfoldable: computed(() => store.state.sidebarUnfoldable),
sidebarVisible: computed(() => store.state.sidebarVisible),
sidebarStore,
sidebarUnfoldable: computed(() => sidebarStore.sidebarUnfoldable),
sidebarVisible: computed(() => sidebarStore.sidebarVisible),
}
},
}
Expand Down
5 changes: 3 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import store from './store'

import CoreuiVue from '@coreui/vue'
import CIcon from '@coreui/icons-vue'
import { iconsSet as icons } from '@/assets/icons'
import DocsExample from '@/components/DocsExample'

const pinia = createPinia()
const app = createApp(App)
app.use(store)
app.use(pinia)
app.use(router)
app.use(CoreuiVue)
app.provide('icons', icons)
Expand Down
21 changes: 0 additions & 21 deletions src/store/index.js

This file was deleted.

29 changes: 29 additions & 0 deletions src/stores/sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'

const useSidebarStore = defineStore('SidebarStore', () => {
const sidebarVisible = ref('')
const sidebarUnfoldable = ref(false)

function toggleSidebar() {
sidebarVisible.value = !sidebarVisible.value
}

function toggleUnfoldable() {
sidebarUnfoldable.value = !sidebarUnfoldable.value
}

function updateSidebarVisible(value) {
sidebarVisible.value = value
}

return {
sidebarVisible,
sidebarUnfoldable,
toggleSidebar,
toggleUnfoldable,
updateSidebarVisible,
}
})

export default useSidebarStore