
state是公共状态
router,//this.router===router
store,//this.store===store
this.$store.state
在{{}}中不用加this:{{$store.state}}
store/index.js
state;{
cityId:1001,
cityName:“sh”
}
carmer.vue
我在:{{$store.state.cityName}}市
本文介绍了如何在Vue项目中使用Vuex进行状态管理,通过具体示例展示了如何定义全局状态并访问这些状态。以cityId和cityName为例,说明了在组件内部如何获取store中的数据。

state是公共状态
router,//this.router===router
store,//this.store===store
this.$store.state
在{{}}中不用加this:{{$store.state}}
store/index.js
state;{
cityId:1001,
cityName:“sh”
}
carmer.vue
我在:{{$store.state.cityName}}市
6919
302

被折叠的 条评论
为什么被折叠?