I'm developing a Vue Application that utilizes Fabric.js to manage the canvas element.
My goal is to control the canvas state through Vuex. To achieve this, I have assigned the fabric canvas instance to a Vuex state variable.
Mutation
setCanvas(state, canv) {
state.canvas = canv
}
Within Vue Component
const canvas = new fabric.Canvas('main-canvas')
this.setCanvas(canvas) //execute the mutation
In another mutation, my task is to add an object to the canvas:
addLayer(state, layer) {
state.canvas.add(layer)
}
Upon executing this mutation, I encounter the following error:
[vuex] do not mutate Vuex store state outside mutation handlers.
My theory is that the fabric.js instance is modifying its properties internally, which Vuex does not permit.
What would be the most effective approach to resolve this issue and properly store the fabric object? Alternatively, is there a more efficient solution available?