Skip to content

Instantly share code, notes, and snippets.

@vitorvargasdev
Created December 21, 2019 02:47
Show Gist options
  • Save vitorvargasdev/e9d0df56d101d4c207f53f6e57d4742a to your computer and use it in GitHub Desktop.
Save vitorvargasdev/e9d0df56d101d4c207f53f6e57d4742a to your computer and use it in GitHub Desktop.
<template>
<div>
<canvas id="canvas"></canvas>
</div>
</template>
<script>
export default {
data() {
return {
img_src: "/images/img_teste1.jpeg",
img_loaded: ''
};
},
methods: {
imgGenerate() {
const img = new Image();
img.src = this.img_src;
img.onload = () => {
this.draw(img);
this.img_loaded = img;
};
},
draw(img) {
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
}
},
mounted() {
this.imgGenerate();
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment