Same image, just one is local, the other is online. Html displays the local image, but nothing on the canvas.
<template>
<div>
<canvas id="canvas" width="300" height="227"></canvas>
<img id="source" src="../assets/sprites/characters/rhino.jpg" style="border:solid red;">
</div>
</template>
<script>
export default {
data() {
return {
}
},
methods: {},
mounted () {
this.$nextTick(() => {
const ctx = document.getElementById('canvas').getContext('2d');
const image = new Image();
image.onload = drawImage;
image.src = 'https://mdn.mozillademos.org/files/5397/rhino.jpg';
//image.src = '../assets/sprites/characters/rhino.jpg';
function drawImage() {
ctx.drawImage(this, 0, 0, 300, 227);
}
})
}
}
</script>
If I uncomment the second image.src, canvas shows nothing. Guessing I'm missing something obvious. Done this a number of times outside of Vue. New to the framework and just grouped code for simplicity, guessing nextTick isn't needed, but tried whatever I could.