We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi Instead of importing SVG files individually, can we use a dynamic import?
For example,
<script setup lang="ts"> import { computed, onBeforeMount, ref } from 'vue'; export interface Props { name: string; /** * In pixels */ size?: number | string; } const props = withDefaults(defineProps<Props>(), { size: 16, }); const iconId = ref(''); const sizeInPx = computed(() => (String(props.size).endsWith('px') ? props.size : `${props.size}px`)); onBeforeMount(async () => { iconId.value = (await import(`../assets/icons/${props.name}.svg`)).default; }); </script> <template> <span :class="$style.container"> <svg :class="$style.svg"> <use :xlink:href="`#${iconId}`"></use> </svg> </span> </template> <style module lang="scss"> .container { width: v-bind(sizeInPx); height: v-bind(sizeInPx); display: block; } .svg { width: 100%; height: 100%; } .container, .svg { color: inherit; } </style>
The text was updated successfully, but these errors were encountered:
It seems to have been implemented indeed.
Sorry, something went wrong.
There is a dynamic import example at https://github.com/meowtec/vite-plugin-svg-sprite/blob/main/examples/vite-svg-sprite-example/src/components/Dynamic.vue#L33 and it works.
No branches or pull requests
Hi
Instead of importing SVG files individually, can we use a dynamic import?
For example,
The text was updated successfully, but these errors were encountered: