I want to share a object between components, class codes are there.
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() {
}
}
someone tell me use vuex, here is my store module codes.
export default{
namespaced:true,
state:{
ide:null
},
mutations:{
setIDE(state,ide){
state.ide = ide
}
},
getters:{
getIDE: state =>{return ide}
}
}
when I try to get my ide object in store
this.$store.state.global.ide.__proto__.setMode('ace/mode/java')
chrome always tell me
TypeError: Cannot read property 'setMode' of undefined
So I view my codes in dev tools
- How I can to call my object like
ide.setMode()? - Can vuex store object? I find many examples of vuex use simple variable like number and string. none of use complex class object.
