[英]Why namespased: false does not work for me
I have seen similar questions.我见过类似的问题。 But I lose something and can't understand why it does not work in my case.
但是我丢失了一些东西并且无法理解为什么它在我的情况下不起作用。 I have the following vuex module:
我有以下 vuex 模块:
const root = {
namespaced: false,
state: {
advertisersOptions: [],
customersTypesOptions: [],
// ... more state props are here ...
},
mutations: {
setIsChoiceAllApps(state, isChoiceAllApps) {
state.isChoiceAllApps = isChoiceAllApps;
},
// and so on
},
getters: {
getErrorMessages: state => {
return state.errorMessages;
},
// and so on
},
actions: {},
};
export default root
I create my store like:我创建我的商店,如:
import Vue from 'vue'
import * as Vuex from 'vuex'
import root from './modules/root'
Vue.use(Vuex);
export const store = new Vuex.Store({
modules: {
root
}
});
And I include it into the app.js
file:我将它包含在
app.js
文件中:
const app = new Vue({
el: '#app',
store,
components: {
Multiselect
},
});
So, I would like to see my vuex properties after ...mapState(['...'])
.所以,我想在
...mapState(['...'])
之后查看我的 vuex 属性。 I will show you the component:我将向您展示组件:
export default {
data() {
return {
choiceAllApplications: false
}
},
methods: {
...mapActions(['updateApplicationsAction']),
disposeAllApps: function () {
this.$store.commit("setApplications", []);
},
},
computed: {
...mapState([
"advertisersOptions",
"advertisersSelected",
// and so on are here
]),
},
As you can see I use namespaced: false,
.如您所见,我使用
namespaced: false,
. I just want to see my properties in the global scope.我只想在全局范围内查看我的属性。 But it does not work.
但它不起作用。 I will make
console.log
inside the mounted()
and this is the dump:我将在
mounted()
创建console.log
,这是转储:
As you can see module name ( root
) is here.如您所见,模块名称 (
root
) 在这里。 I forgot something?我忘记了什么?
You didn't forgot anything, it is always like this - as per Vuex docs , only getters, setters and actions
are subject to be namespaced (and, btw, even then they are namespaces, they will still be present in global object but be like moduleName/action
- user/getUserName
and not inside objects like user.getUserName
).你没有忘记任何东西,它总是这样 - 根据Vuex 文档,只有
getters, setters and actions
受命名空间的约束(顺便说一句,即使它们是命名空间,它们仍然会出现在全局对象中,但是像moduleName/action
- user/getUserName
而不是像user.getUserName
这样的对象内部)。
However state
is always per module - so, not matter namespaced or not it will sit in it's own property in the global state object.然而,
state
总是每个模块 - 因此,无论是否命名空间,它都将位于全局状态对象中它自己的属性中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.