To use ZIM in a Vue application, you can either use the zim namespace or use zim.zimplify() to make ZIM commands global. It is recommended to initialize the zim.Frame within the onMounted lifecycle hook and call frame.dispose() within onBeforeUnmount to prevent memory leaks.
With zim namespace
Import zim from zimjs and access classes via new zim.Frame() and new zim.Circle().
Without zim namespace
Call zim.zimplify() to make ZIM commands global, allowing you to use new Frame() and new Circle() directly.
// With zim namespace
<script setup>
import { onMounted, onBeforeUnmount } from "vue";
import zim from "zimjs";
let frame;
onMounted(() => {
frame = new zim.Frame({
scaling: "zim",
width: 500,
height: 400,
color: light,
ready: () => {
new zim.Circle(50, red).center().drag();
}
});
});
onBeforeUnmount(() => {
frame.dispose();
});
</script>
<template>
<div id="zim"></div>
</template>