vue2-vuex

1.cnpm install vuex

2.入口文件中加入(main.js)

import Vue from 'vue'

import App from './vuex'

import store from './store'

new Vue({

el: '#app',

store,

render: h => h(App)

})


3.新建的文件store.js 中加入

import Vue from 'vue'

import Vuex from 'vuex';

Vue.use(Vuex)

const state={

count:411

}

// 这个是外加的方法

const mutations = {

jia(state){

state.count ++;

},

jian(state){

state.count --

}

}

// 这个是外加的方法

export default new Vuex.Store({

state,

mutations

})


4.在新建的vuex文件中加入代码


vue2-vuex_第1张图片

上述文件都是同级目录下新建 的

你可能感兴趣的:(vue2-vuex)