vue.js - 在没有 mapState 的情况下调用 vuex store

标签 vue.js vuex

所以我正在试验一个使用 vue cli 创建的新项目,我在其中使用路由器和 VueX

所以在我的 HelloWorld.vue 文件中,我在脚本部分有这段代码:

import { mapState } from 'vuex'

export default {
  name: 'hello',
   computed: mapState({
    msg: 'nombre'
  }),

是否有更直接的方式调用状态中的值?例如我想做的

msg: store.nombre

我的 vuex 存储在根 main.js 中定义如下:

//vuex
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    nombre: "POS vuex"
  }  
});

new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})

最佳答案

其实我是这样找的:

msg: this.$store.state.nombre

(我错过了“.state.”部分)

关于vue.js - 在没有 mapState 的情况下调用 vuex store,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51637069/

相关文章:

javascript - Vuex 计算属性不更新 v-show

vue.js - 在单元测试中抑制 Vue 警告

unit-testing - 使用 `Updated` 钩子(Hook)与 `vue-test-utils` 和 `jest` 进行测试

javascript - Vue Typescript 组件库 - 使用 Webpack 和 SASS

vue.js - Vuex 模块初始化最佳实践

javascript - Nuxtjs 页面未收到 Pusher 事件

javascript - 从 Vuex 更新数据在观察者中出现无限循环

nuxt.js - 我可以使用 Nuxt Apollo 本地状态来完全替代 Vuex 吗?

javascript - Mutation 不会更新 VUEX 中的 store

vue.js - Vuex 模块变更