【发布时间】:2016-12-18 06:17:16
【问题描述】:
在使用 webpack (1.13.1) 和 vue-loader (8.5.3) 构建的 vue.js (1.0.26) 应用程序中, 导入只是 svg 一部分的组件时出现问题。
here is a repo with this problem
父组件:
<template>
<svg viewBox="0 0 1280 512">
<axis-x></axis-x>
</svg>
</template>
<script>
import axisX from './axis-x.vue';
export default {
components: {
axisX
}
}
</script>
子组件:
<template>
<g>
<line x1="1" y1="400" x2="1" y2="416" style="stroke:black;stroke-width:1" />
<text x="16" y="414" fill="black">1990</text>
</g>
</template>
<script>
export default {
};
</script>
webpack 运行时会报如下错误:
ERROR in ./src/axis-x.vue
2 | <g>
3 | <line x1="1" y1="400" x2="1" y2="416" style="stroke:black;stroke-width:1" />
| ^
4 | <text x="16" y="414" fill="black">1990</text>
Invalid self-closing tag: <line x1="1" y1="400" x2="1" y2="416" style="stroke:black;stroke-width:1" />.
This will be treated as the starting tag only in HTML5. Use <line></line> instead.
看起来加载器将 svg 部分解释为无效的 HTML。
我该如何解决这个问题?谢谢
【问题讨论】:
-
收盘行有效?
-
它确实有效……但它仍然是有效的 SVG 吗?
-
是的,你也可以放其他元素stackoverflow.com/a/2529032/4690316
-
好的,谢谢。我现在会这样做,但我仍然想找到一种使用自闭合 svg 元素的方法。
标签: svg webpack vue.js vue-loader