这是我第一次发问。如果我不知道所有的礼节,请冷静点。我正在使用我在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>和<path>标记,我的应用程序会编译得很好。当我点击SVG作为加载页面在我的应用程序,它显示很好,但动画不工作。
我对SVG和CDATA非常陌生,对我来说是100%的新鲜事。任何帮助都将不胜感激。谢谢!
编辑:我仍然不知道为什么,但删除包装<]标签,并保持CSS样式修复我的问题。
发布于 2020-07-26 18:53:18
我也是新来的,但我找到了一个简单的解决方案,我希望这对你有用,这对我仍然有效。

中。


。
return (
<div className={styles.App}>
<object data={Test} />
</div>
)在这种情况下,您不需要从任何地方删除任何东西,很简单,但希望这样做对您有用。
https://stackoverflow.com/questions/63094130
复制相似问题