标签:class lan from 项目 his state script method const
VUEX
1、安装
cnpm install vuex--save
2、导入,src下新建一个文件夹vuex,文件夹下新建一个store.js
import Vue from ‘vue‘
import Vuex from ‘vuex‘
Vue.use(Vuex);
3、state 相当于vue项目的data
var state={
count:1
}
4、mutations相当于vue中的 methods
var mutations={
incCount(){
++state.count;
}
}
5、暴露,实例化
const store =new Vuex.Store({
state,
mutations:mutations
})
export default store;
6、使用
<script>下面
import store from ‘../vuex/store.js‘;
<template>中
{{this.$store.state.count}}
7、一种提交概念
methods:{
inCount(){
this.$store.commit(‘incCount‘);
}
}
标签:class lan from 项目 his state script method const
原文地址:https://www.cnblogs.com/ju-ruo/p/14876520.html