Currently, I am tackling a project in vue.js (version 3) and find myself in a situation where I need to incorporate the HTML output of one component into another component's method.
In my Vue project, I have developed an SVG component as shown below:
CircleWithTextSvg.vue
<template>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd" width="20" height="20">
<g id="UrTavla">
<circle cx="10" cy="10" r="10" stroke="gray" stroke-width="1" :fill="fill" />
<text x="50%" y="50%" text-anchor="middle" stroke="black" stroke-width="1px" dy=".3em">{{text}}</text>
</g>
</svg>
</template>
<script>
export default {
props: {
text: {
type: String,
default: "1"
},
fill: {
type: String,
default: "white"
}
}
}
</script>
This specific component displays a circle with text inside it. When added to the template section of my main component, as shown below, it functions correctly.
MainComponent.vue
<template>
<circle-with-text-svg />
</template>
However, I am looking to provide this rendered SVG component output as a parameter to a third-party entity.
Real Use Case:- The intention behind creating this separate component was to showcase it as a marker on my leaflet map. The issue arises when I try to embed this SVG component within the method of my MainComponent so I can utilize it as an option for L.divIcon
When attempting the following:
export default {
methods: {
generateMap(element) {
// ...
let icon = L.divIcon({
html: <circle-with-text-svg
fill="'#D3D5FF'"
text="1" />,
iconSize: [10, 10]
});
// ...
}
}
}
I encounter the errors:
The experimental syntax 'JSX isn't currently enabled
In React, incorporating components within another component's template is straightforward. Nevertheless, how can we accomplish this in vue.js?
Based on the error message, it appears that JSX experimental mode has not been activated.
Could someone guide me on how to resolve this challenge?