[Vuejs]-In Vue CLI, the defined variable inside the data property does not work, when used with this.VariableName

0👍

Use computed property instead of data

Instead of storing var canvas inside data(), I stored it inside computed:. Therefore, I used the following code:

computed: {
    canvas() {
      return new fabric.Canvas("canvas", { isDrawingMode: true });
    }
  },

In methods: I then used:

this.canvas.clear();

See the whole updated code on Codepen.io

Leave a comment