Vue 3 - Svgator player is always undefined.
<p>Currently, I used SVGator to create an SVG animation. <br />I imported it as a resource into my application and tried to get it running. </p><p>I followed the instructions in this document and successfully implemented it. </p><p>However, since I may need to create a large number of animations, I tried to make it more general. </p><p><br /></p>
<pre class="brush:js;toolbar:false;"><script setup lang="ts">
import { ref, defineComponent, h, component, watch } from 'vue';
import exampleSvg from '@assets/example.svg?raw';
interface IComponentProperties {
svg: string;
}
const componentProperties = withDefaults(defineProps<IComponentProperties>(), {
svg: () => exampleSvg,
});
const element = ref<HTMLElement>();
const animatedSvg = defineComponent({
render() {
return h('svg', { innerHTML: componentProperties.svg, ref: element });
},
});
function runAnimation() {
if (!element.value) return;
const { firstChild } = element.value;
const svg = firstChild as any;
svg?.svgatorPlayer?.play();
}
watch(
() => element.value,
() => {
runAnimation();
},
{
immediate: true,
}
);
</script>
<template>
<Component :is="animatedSvg" />
</template>
</pre>
<p>This is a complete Vue application containing the same code. </p><p>Why is svg?.svgatorPlayer always null? </p><p><strong></strong></p>