mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
Add vuex-persistedstate example
This commit is contained in:
parent
8dca358216
commit
ef4cdd4776
3
examples/vuex-persistedstate/README.md
Normal file
3
examples/vuex-persistedstate/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Nuxt.js with Vuex persisted state (localStorage)
|
||||||
|
|
||||||
|
See https://github.com/robinvdvleuten/vuex-persistedstate
|
6
examples/vuex-persistedstate/nuxt.config.js
Normal file
6
examples/vuex-persistedstate/nuxt.config.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module.exports = {
|
||||||
|
/*
|
||||||
|
** We set `spa` mode to have only client-side rendering
|
||||||
|
*/
|
||||||
|
mode: 'spa'
|
||||||
|
}
|
12
examples/vuex-persistedstate/package.json
Normal file
12
examples/vuex-persistedstate/package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "nuxt-vuex-store",
|
||||||
|
"dependencies": {
|
||||||
|
"nuxt": "^1.0.0-rc6",
|
||||||
|
"vuex-persistedstate": "^2.0.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"dev": "nuxt",
|
||||||
|
"build": "nuxt build",
|
||||||
|
"start": "nuxt start"
|
||||||
|
}
|
||||||
|
}
|
22
examples/vuex-persistedstate/pages/index.vue
Normal file
22
examples/vuex-persistedstate/pages/index.vue
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<p>{{ counter }}</p>
|
||||||
|
<p>
|
||||||
|
<button @click="increment">+</button>
|
||||||
|
<button @click="decrement">-</button>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { mapState, mapMutations } from 'vuex'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
computed: {
|
||||||
|
...mapState(['counter'])
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapMutations(['increment', 'decrement'])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
14
examples/vuex-persistedstate/store/index.js
Normal file
14
examples/vuex-persistedstate/store/index.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import createPersistedState from 'vuex-persistedstate'
|
||||||
|
|
||||||
|
export const state = () => ({
|
||||||
|
counter: 0
|
||||||
|
})
|
||||||
|
|
||||||
|
export const mutations = {
|
||||||
|
increment: (state) => state.counter++,
|
||||||
|
decrement: (state) => state.counter--
|
||||||
|
}
|
||||||
|
|
||||||
|
export const plugins = [
|
||||||
|
createPersistedState()
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user