所以我正在试验一个使用 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/