Javascript 我可以使用Vuex存储我自己的类对象吗?

Javascript 我可以使用Vuex存储我自己的类对象吗?,javascript,vue.js,vuex,Javascript,Vue.js,Vuex,我想在组件之间共享一个对象,有类代码 class IDE { constructor(id) { config.set('basePath', 'static/js/ace'); this.aceEditor = edit(id); this.aceSession = this.aceEditor.session; this.aceSession.setMode("ace/mode/javascript"); this.aceEditor.setTheme

我想在组件之间共享一个对象,有类代码

class IDE {
constructor(id) {
    config.set('basePath', 'static/js/ace');
    this.aceEditor = edit(id);
    this.aceSession = this.aceEditor.session;
    this.aceSession.setMode("ace/mode/javascript");
    this.aceEditor.setTheme('ace/theme/monokai');
    this.aceEditor.setShowPrintMargin(false);
}
setMode() {

}
}
有人告诉我使用vuex,这是我的存储模块代码

export default{
namespaced:true,
state:{
    ide:null
},
mutations:{
    setIDE(state,ide){
        state.ide = ide
    }
},
getters:{
    getIDE: state =>{return ide}
}
}
当我尝试在商店中获取ide对象时

这个.store.state.global.ide.\uuuuu proto\uuuuuu.setMode('ace/mode/java'))

我总是告诉我

TypeError:无法读取未定义的属性“setMode”

因此,我在开发工具中查看我的代码

  • 如何调用我的对象,如
    ide.setMode()
  • vuex可以存储对象吗? 我发现许多vuex示例使用简单的变量,如数字和字符串。它们都不使用复杂的类对象

  • 这将是
    getIDE:state=>state.ide
    @Matt你是对的,它工作了,但我想知道为什么,在那里有`` getter:{doneTodos:state=>{return state.todos.filter(todo=>todo.done)}“`` doneTodos有return,我写我的代码遵循它,但是为什么我不能写return?没有大括号的箭头函数可以让你省略
    return
    -如果你愿意,你可以使用
    return
    ,但是你原始代码中的关键问题是
    return ide;
    而不是
    return state.ide;
    @Matt谢谢你,它很好,你真棒