# 数据流 为了更好地理解 Vuex app 中的数据流,我们来开发一个简单的计数器 app。注意:这个例子仅仅是为了更好地解释概念,在实际情况中并不需要在这种简单的场合使用 Vuex. ### 引入并加载 Vuex ``` js // store.js import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) ``` ### 定义 App State ``` js const state = { count: 0 } ``` ### 定义会被用到的 State Mutations ``` js const mutations = { INCREMENT (state) { state.count++ }, DECREMENT (state) { state.count-- } } ``` ### 定义可被调用的 Actions ``` js const actions = { increment: 'INCREMENT', decrement: 'DECREMENT' } ``` ### 创建 Store 实例 ``` js export default new Vuex.Store({ state, mutations, actions }) ``` ### 在 Vue 组件里使用 **Template** ``` html