reactjs - 从 SVGator 导出的文件无法在 React 中编译
问题描述
这是我第一次发布问题。如果我不了解所有礼仪,请保持冷静。我正在使用内置 SVGator 的 SVG 动画。我将它作为加载页面加载到我的反应应用程序中。
SVG 文件本身在浏览器中显示良好,但是当我将它加载到我的 React 应用程序中时,我收到错误消息:
Failed to compile.
./src/assets/Loadingpage.svg (./node_modules/@svgr/webpack/lib?-svgo,+titleProp,+ref!./src/assets/Loadingpage.svg)
Error: Expected node, got `#eba7ha49d1l68_to {animation: eba7ha49d1l68_to__to 3000ms linear infinite normal forwards}@keyframes eba7ha49d1l68_to__to { 0% {transform: translate(0px,0px);animation-timing-function: cubic-bezier(0.420000,0,1,1)} 16.666667% {transform: translate(0px,-50px)} 33.333333% {transform: translate(0px,-100px)} 100% {transform: translate(0px,-100px)} }#eba7ha49d1l68 {animation: eba7ha49d1l68_c_o 3000ms linear infinite normal forwards}@keyframes eba7ha49d1l68_c_o { 0% {opacity: 0;animation-timing-function: cubic-bezier(0.420000,0,1,1)} 23.333333% {opacity: 1} 33.333333% {opacity: 0} 100% {opacity: 0} }#eba7ha49d1l69_to {animation: eba7ha49d1l69_to__to 3000ms linear infinite normal forwards}@keyframes eba7ha49d1l69_to__to { 0% {transform: translate(0px,0px)} 40% {transform: translate(0px,0px);animation-timing-function: cubic-bezier(0.420000,0,1,1)} 56.666667% {transform: translate(0px,-50.003000px)} 73.333333% {transform: translate(0px,-100.003000px)} 100% {transform: translate(0px,-100.003000px)} }#eba7ha49d1l69 {animation: eba7ha49d1l69_c_o 3000ms linear infinite normal forwards}@keyframes eba7ha49d1l69_c_o { 0% {opacity: 0} 40% {opacity: 0;animation-timing-function: cubic-bezier(0.420000,0,1,1)} 63.333333% {opacity: 1} 73.333333% {opacity: 0} 100% {opacity: 0} }`
这将我指向文件顶部的这个 CDATA:
<style>
<![CDATA[#eba7ha49d1l68_to {
animation: eba7ha49d1l68_to__to 3000ms linear infinite normal forwards
}
@keyframes eba7ha49d1l68_to__to {
0% {
transform: translate(0px, 0px);
animation-timing-function: cubic-bezier(0.420000, 0, 1, 1)
}
16.666667% {
transform: translate(0px, -50px)
}
33.333333% {
transform: translate(0px, -100px)
}
100% {
transform: translate(0px, -100px)
}
}
#eba7ha49d1l68 {
animation: eba7ha49d1l68_c_o 3000ms linear infinite normal forwards
}
@keyframes eba7ha49d1l68_c_o {
0% {
opacity: 0;
animation-timing-function: cubic-bezier(0.420000, 0, 1, 1)
}
23.333333% {
opacity: 1
}
33.333333% {
opacity: 0
}
100% {
opacity: 0
}
}
#eba7ha49d1l69_to {
animation: eba7ha49d1l69_to__to 3000ms linear infinite normal forwards
}
@keyframes eba7ha49d1l69_to__to {
0% {
transform: translate(0px, 0px)
}
40% {
transform: translate(0px, 0px);
animation-timing-function: cubic-bezier(0.420000, 0, 1, 1)
}
56.666667% {
transform: translate(0px, -50.003000px)
}
73.333333% {
transform: translate(0px, -100.003000px)
}
100% {
transform: translate(0px, -100.003000px)
}
}
#eba7ha49d1l69 {
animation: eba7ha49d1l69_c_o 3000ms linear infinite normal forwards
}
@keyframes eba7ha49d1l69_c_o {
0% {
opacity: 0
}
40% {
opacity: 0;
animation-timing-function: cubic-bezier(0.420000, 0, 1, 1)
}
63.333333% {
opacity: 1
}
73.333333% {
opacity: 0
}
100% {
opacity: 0
}
}
]]>
</style>
当我将其注释掉时,它似乎修复了我整个文档中的其余<rect>
and<path>
标记,并且我的应用程序可以正常编译。当我在我的应用程序中将 SVG 作为加载页面点击时,它显示正常,但动画不起作用。
我对使用 SVG 还是很陌生,而 CDATA 对我来说是 100% 的新手。任何帮助将不胜感激。谢谢!
编辑:我仍然不确定为什么,但删除包装 <![CDATA...]]> 标签并保持 CSS 样式解决了我的问题。
解决方案
推荐阅读
- javascript - JavaScript Settings - What are these called?
- python - 将字符串 DateTime 变量转换为真实的 Datetime 变量(Python)
- laravel-5.2 - 找不到数据库异常基表或视图
- java - Java Set Iterator#remove() 或 Set#clear() 之后?
- highcharts - 是否可以使用 highcharter 创建词云?
- ios - 为什么出口不能在 initWithCoder 中初始化?
- powershell - 如何在新的隐藏窗口中启动此 PowerShell 脚本
- c# - 无法创建多个 AppDomain
- javascript - 在 HTML5 画布上绘图:如何在鼠标光标尖端绘图
- rust - 如何正确使用 std::arch::_mm_loadu_si128 / _mm_storeu_si128