普通方式
使用普通方式的状态树,需要添加 store/index.js 文件,并对外暴露一个 Vuex.Store 实例:

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = () => new Vuex.Store({
    state: {
        count: 0
    },
    mutations: {
        add(state) {
            state.count++
        }
    }
})

export default store

在组件里面

 <div @click="$store.commit('add')">你好啊 点我变大大{{$store.state.count}}</div>
posted on 2020-03-18 14:44  周小姐你好  阅读(2122)  评论(0编辑  收藏  举报