diff --git a/src/components/Image/BlurhashImg.vue b/src/components/Image/BlurhashImg.vue index 306efdc87..fa93943f3 100644 --- a/src/components/Image/BlurhashImg.vue +++ b/src/components/Image/BlurhashImg.vue @@ -18,25 +18,21 @@ const props = withDefaults( const canvas = ref(undefined); onMounted(() => { - try { - if (canvas.value) { - const pixels = decode(props.hash, 128, 32); - const imageData = new ImageData(pixels, 128, 32); - const context = canvas.value.getContext("2d"); - if (context) { - context.putImageData(imageData, 0, 0); - } - } + updateCanvas(); +}); - @Watch("hash") - updateHashChange(): void { - try { - const pixels = decode(this.hash, 128, 32); - const imageData = new ImageData(pixels, 128, 32); - const context = this.canvas.getContext("2d"); - context.putImageData(imageData, 0, 0); +watch(() => props.hash, () => { + updateCanvas(); +}); + +function updateCanvas() { + try { + const pixels = decode(props.hash, 128, 32); + const imageData = new ImageData(pixels, 128, 32); + const context = canvasRef.value.getContext('2d'); + context.putImageData(imageData, 0, 0); } catch (e) { console.error(e); } -}); +} diff --git a/src/components/Image/BlurhashImgWrapper.vue b/src/components/Image/BlurhashImgWrapper.vue index 8a6b15b01..c1bb3a555 100644 --- a/src/components/Image/BlurhashImgWrapper.vue +++ b/src/components/Image/BlurhashImgWrapper.vue @@ -10,71 +10,37 @@ - -