Showing
2 changed files
with
34 additions
and
29 deletions
| 1 | import Vue from 'vue' | 1 | import Vue from 'vue' |
| 2 | -import Vuex from 'vuex' | ||
| 3 | import App from './App.vue' | 2 | import App from './App.vue' |
| 4 | - | 3 | +import store from './store.js' |
| 5 | -Vue.use(Vuex) | ||
| 6 | - | ||
| 7 | -const store = new Vuex.Store({ | ||
| 8 | - state: { | ||
| 9 | - count: 0, | ||
| 10 | - size: 10, | ||
| 11 | - isLogin: false, | ||
| 12 | - todos: [ | ||
| 13 | - { id: 1, text: '...', done: true }, | ||
| 14 | - { id: 2, text: '...', done: false } | ||
| 15 | - ] | ||
| 16 | - }, | ||
| 17 | - getters: { | ||
| 18 | - doneTodos: state => { | ||
| 19 | - return state.todos.filter(todo => todo.done) | ||
| 20 | - } | ||
| 21 | - }, | ||
| 22 | - mutations: { | ||
| 23 | - increment: state => state.count++, | ||
| 24 | - decrement: state => state.count--, | ||
| 25 | - login: state => state.isLogin = true | ||
| 26 | - } | ||
| 27 | -}) | ||
| 28 | 4 | ||
| 29 | new Vue({ | 5 | new Vue({ |
| 30 | el: '#app', | 6 | el: '#app', |
| 31 | store, | 7 | store, |
| 32 | render: h => h(App) | 8 | render: h => h(App) |
| 33 | }) | 9 | }) |
| 34 | - | ||
| 35 | -export { | ||
| 36 | - store | ||
| 37 | -} | ... | ... |
src/store.js
0 → 100644
| 1 | +import Vue from 'vue' | ||
| 2 | +import Vuex from 'vuex' | ||
| 3 | + | ||
| 4 | +Vue.use(Vuex) | ||
| 5 | + | ||
| 6 | +const store = new Vuex.Store({ | ||
| 7 | + state: { | ||
| 8 | + count: 0, | ||
| 9 | + size: 10, | ||
| 10 | + isLogin: false, | ||
| 11 | + todos: [{ | ||
| 12 | + id: 1, | ||
| 13 | + text: '...', | ||
| 14 | + done: true | ||
| 15 | + }, { | ||
| 16 | + id: 2, | ||
| 17 | + text: '...', | ||
| 18 | + done: false | ||
| 19 | + }] | ||
| 20 | + }, | ||
| 21 | + getters: { | ||
| 22 | + doneTodos: state => { | ||
| 23 | + return state.todos.filter(todo => todo.done) | ||
| 24 | + } | ||
| 25 | + }, | ||
| 26 | + mutations: { | ||
| 27 | + increment: state => state.count++, | ||
| 28 | + decrement: state => state.count--, | ||
| 29 | + login: state => state.isLogin = true | ||
| 30 | + } | ||
| 31 | +}) | ||
| 32 | + | ||
| 33 | +export default store |
-
Please register or login to post a comment