UNPKG

673 BJavaScriptView Raw
1import Vue from 'vue'
2import Vuex from 'vuex'
3
4const state = {
5 data: [{text: 'text'}, {text: 'text2'}],
6 data1: {
7 name: 'peter'
8 },
9 data2: 1000
10}
11
12const actions = {
13 changeText({ commit, state }, text) {
14 commit('change', text);
15 }
16}
17
18const mutations = {
19 change(state, text) {
20 state.data1.name += text;
21 },
22 addList(state, text){
23 state.data.push({
24 text: text
25 });
26 }
27}
28
29Vue.use(Vuex)
30
31export default new Vuex.Store({
32 state,
33 actions,
34 mutations,
35 getters: {
36 data: state => {
37 return state.data
38 },
39 data1: state => {
40 return state.data1
41 },
42 data2: state => {
43 return state.data2
44 }
45 }
46})