Стивен Томас поделился действительным решением со своей ссылкой на загрузку встроенного svg .
Что будет выглядеть следующим образом в Vue.
Скажем, бэкэнд возвращает следующий SVG (обратите внимание на fill="currentColor"
):
<svg aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 384 512">
<path fill="currentColor"
d="M323.1 441l53.9-53.9c9.4-9.4 9.4-24.5 0-33.9L279.8 256l97.2-97.2c9.4-9.4 9.4-24.5 0-33.9L323.1 71c-9.4-9.4-24.5-9.4-33.9 0L192 168.2 94.8 71c-9.4-9.4-24.5-9.4-33.9 0L7 124.9c-9.4 9.4-9.4 24.5 0 33.9l97.2 97.2L7 353.2c-9.4 9.4-9.4 24.5 0 33.9L60.9 441c9.4 9.4 24.5 9.4 33.9 0l97.2-97.2 97.2 97.2c9.3 9.3 24.5 9.3 33.9 0z"></path>
</svg>
Вы можете создать очень простой компонент изображения SVG:
<template>
<span v-html="content" />
</template>
<script>
export default {
props: {
src: {
type: String,
required: true,
}
},
data() {
return {content: ''};
},
watch: {
src: {
immediate: true,
handler(src) {
axios(src).then((response) => this.content = response.data);
}
}
},
}
</script>
Затем используйте его, когда вам это нужно:
<template>
<svg-img :src="svgSrc" />
</template>
<script>
import SvgImg from './components/SvgImg.vue';
export default {
components: {
SvgImg
},
data: {
svgSrc: 'url/to/backend/times.svg',
},
}
</script>