相关疑难解决方法(0)

如何在 Nuxt 应用程序中包含内联 .svg

我想做一件常见的事情 - 在 Vue Nuxt 应用程序中动态包含一个 svg HTML,我将能够对其进行样式设置。为此,我创建了一个组件,但不是图像,而是文本data:image/svg+xhtml...

如何使它工作?

<template>
   <div v-html="src"></div>
</template>
<script>
export default {
    name: 'Icon',
    props: {
        name: {
            type: String,
            required: true
        }
    },
    computed: {
        src() {
            const src = require(`assets/icons/${this.name}.svg`)
            return src
        }
    }
}
</script>
Run Code Online (Sandbox Code Playgroud)

html svg webpack vue.js nuxt.js

5
推荐指数
2
解决办法
7737
查看次数

标签 统计

html ×1

nuxt.js ×1

svg ×1

vue.js ×1

webpack ×1