Я пытаюсь создать элемент canvas в vue. У меня проблемы с экземпляром canvas. Я считаю, что я не декларирую или не использую это должным образом. Я получаю следующую ошибку:
Ошибка типа: невозможно установить для свойства 'linewidth' значение null в VueComponent.draw (HelloWorld. vue? 140d: 55)
Как могу ли я получить доступ к
Моему шаблону:
<div id="app">
<canvas
v-on:mousedown="startPainting()"
v-on:mouseup="finishedPainting()"
v-on:mousemove="draw()"
id="canvas"
></canvas>
</div>
Моему js
<script>
export default {
name: "HelloWorld",
data: () => ({
canvas: null,
ctx: null,
message: "Henlo vue!",
vueCanvas: null,
painting: false
}),
mounted() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
this.vueCanvas = ctx;
},
methods: {
startPainting: function() {
this.painting = true;
console.log(this.painting);
},
finishedPainting: function() {
this.painting = false;
console.log(this.painting);
},
draw: function(e) {
if (this.painting) {
console.log("henlo painting!");
this.ctx.linewidth = 10;
this.ctx.lineCap = "round";
this.ctx.linTo(e.clientX, e.clientY);
this.ctx.stroke();
}
}
}
};
</script>