NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[vuex](https://vuex.vuejs.org/zh/) ![](https://box.kancloud.cn/288a0dc913bab3fe765baf18fb4bac27_701x551.png) ## 1.NPM安装 ~~~ npm install vuex --save ~~~ ## 2.`src`目录下新建`store.js`的文件 ~~~ import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) export default new Vuex.Store({ state: { city:'天门' }, mutations: { }, actions: { } }) ~~~ ## 3.在组件中使用vuex的数据 ~~~ <div class="button">{{this.$store.state.city}}</div> ~~~