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>