1.安装Vuex
npm install --save vuex
2.配置文件
import { createStore} from 'vuex'
export default createStore({
state:{
count:0
}
})
3.在主文件夹中引入Vuex
import store from './store'
app.use(store)
4.在组件中读取状态
第一种:<p>count:{{$store.state.count}}</p>
第二种:import {mapState} from 'vuex';
computed:{
...mapState({'count'})
}