79321581

Date: 2025-01-01 12:28:50
Score: 1.5
Natty:
Report link

Composition API version of the code provided by @ben-winding.

<template>
    <canvas ref="can" width="200" height="200"></canvas>
</template>

<script setup>
import { useTemplateRef, onMounted } from "vue";
import { fabric } from "fabric";

const can = useTemplateRef("can")

onMounted(() => {
    const canvas = new fabric.Canvas(can.value)
    const rect = new fabric.Rect({
        fill: 'red',
        width: 20,
        height: 20
    });
    canvas.add(rect);
})
</script>
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @ben-winding
  • Low reputation (1):
Posted by: holy-jesus