I'm creating a Vue Application that uses Fabric.js to manage the canvas.
I want to manage the canvas state using Vuex. For this, I set the fabric canvas instance to a vuex state variable.
Mutation
setCanvas(state, canv) {
state.canvas = canv
}
In Vue Component
const canvas = new fabric.Canvas('main-canvas')
this.setCanvas(canvas) //commit the mutation
In another mutation I have to add an object to the canvas:
addLayer(state, layer) {
state.canvas.add(layer)
}
When running this mutation I get the following error:
[vuex] do not mutate Vuex store state outside mutation handlers.
I think the reason is that fabric js instance is editing props in itself. And vuex does not seem to like this.
What is the best way to store the fabric object for this problem ? or is there a better way to solve it?