I try to create a new Object of an Class at a click on a Button and want to store this Object in the vuex state. For Example, when a button is clicked, it calls the method "newMine()":
newMine() {
this.$store.dispatch('setNewMine',"Iron")
}
in the Store, i have this action:
import { Mine } from './modules/mine'
...
state: {
mines:[]
},
mutations: {
setNewMine(state,ore){
state.mines.push(new Mine(ore))
}
},
actions: {
setNewMine({commit},ore){
commit('setNewMine',ore)
}
},
getters: {
getMines:(state) =>{
return state.mines
}
}
the class "Mine" looks like this:
export default class Mine {
constructor(id,wert){
this.id = id
this.wert = wert
}
get id(){
return this.id
}
set id(id) {
this.id = id
}
get wert(){
return this.wert
}
set wert(wert) {
this.id = wert
}
}
It should be really simple, but it still doesnt work, because i get the error message:
[Vue warn]: Error in v-on handler: "TypeError: _modules_mine__WEBPACK_IMPORTED_MODULE_3__.Mine is not a constructor"
Whats wrong here? Any help is welcomed, even if it without the store. Thank you