容器中的 state ⽤于存储需要在组件间共享的数据,特点如下: 容器中的数据可以被任意组件访问。 容器中的数据为响应式数据。 // store/index.js import Vue from ‘vue’ import Vuex from ‘vuex’ Vue.use(Vuex) export default new Vuex.Store({ state: { user: 100 }, mutations: { }, actions: { }, modules: { } }) 在浏览器中查看 Vue DevTools 的 Vuex 选项卡可以看到 Vuex 管理的状态。 在组件中通过 vm.$store.state.状态名 访问。 // login/index.vue methods: { async onSubmit () { console.log(this.$store.state.user) … } }