Skip to content

Commit

Permalink
examples: improve vuex store example (#5017)
Browse files Browse the repository at this point in the history
  • Loading branch information
manniL authored and clarkdo committed Feb 19, 2019
1 parent b1753e4 commit a9511e5
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 115 deletions.
7 changes: 0 additions & 7 deletions examples/vuex-store-modules/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions examples/vuex-store-modules/package.json

This file was deleted.

12 changes: 0 additions & 12 deletions examples/vuex-store-modules/pages/about.vue

This file was deleted.

45 changes: 0 additions & 45 deletions examples/vuex-store-modules/pages/index.vue

This file was deleted.

9 changes: 0 additions & 9 deletions examples/vuex-store-modules/store/index.js

This file was deleted.

8 changes: 4 additions & 4 deletions examples/vuex-store/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Nuxt with [Vuex](https://vuex.vuejs.org/)
# Nuxt with [Vuex](https://vuex.vuejs.org/) and store modules

> Vuex is a state management pattern + library for Vue.js applications.
>Vuex is a state management pattern + library for Vue.js applications.
Read on Vuex modules [here](https://vuex.vuejs.org/guide/modules.html)


https://nuxtjs.org/examples/vuex-store
https://nuxtjs.org/guide/vuex-store#modules-files
30 changes: 21 additions & 9 deletions examples/vuex-store/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
<template>
<div>
<p>
<button @click="increment">
{{ counter }}
</button><br>
<NuxtLink to="/about">
About
</NuxtLink>
</p>
<h3>Index Module</h3>
<button @click="increment">
{{ counter }}
</button>
<br>
<NuxtLink to="/about">
About
</NuxtLink>
<br>
<br>
<h3>Todo Module</h3>
<NuxtLink to="/todos">
Todos
</NuxtLink>
<br>
<br>
<h3>Nested Modules</h3>
<NuxtLink to="/website">
Website
</NuxtLink>
</div>
</template>

Expand All @@ -19,7 +31,7 @@ export default {
'counter'
]),
// fetch(context) is called by the server-side
// and nuxt before instantiating the component
// and before instantiating the component
fetch({ store }) {
store.commit('increment')
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ export const state = () => ({
]
})

export const mutations = {
add(state, title) {
state.list.push(title)
}
}

export const getters = {
get(state) {
return state.list
Expand Down
5 changes: 5 additions & 0 deletions examples/vuex-store/store/articles/comments/mutations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
add(state, title) {
state.list.push(title)
}
}
5 changes: 5 additions & 0 deletions examples/vuex-store/store/todos/getters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
todos(state) {
return state.list
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export const state = () => ({
list: []
})

export const mutations = {
export default {
add(state, { text }) {
state.list.push({
text,
Expand All @@ -14,9 +10,3 @@ export const mutations = {
todo.done = !todo.done
}
}

export const getters = {
todos(state) {
return state.list
}
}
3 changes: 3 additions & 0 deletions examples/vuex-store/store/todos/state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => ({
list: []
})

0 comments on commit a9511e5

Please sign in to comment.