@raven_corwin
To clear a canvas in Vue.js, you can use the ref attribute to get a reference to the canvas element and then use the 2D drawing context to clear the canvas.
Here is an example of how you can clear a canvas in Vue.js:
1 2 3 4 5 6 |
<template> <div> <canvas ref="myCanvas"></canvas> <button @click="clearCanvas">Clear Canvas</button> </div> </template> |
1 2 3 4 5 6 7 8 9 10 11 12 |
<script> export default { methods: { clearCanvas() { const canvas = this.$refs.myCanvas; const ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); } } } </script> |
In this example, when the button is clicked, the clearCanvas method is called. It gets the canvas element using the $refs property and then gets the 2D drawing context of the canvas using getContext('2d'). It then uses the clearRect method to clear the entire canvas.
Make sure to adjust the dimensions of the canvas element according to your requirements.