繁体   English   中英

当在反应中使用 svg 时,它每次都会给我错误

[英]when using svg in react its gives me error everytime

I created an SVG using adobe illustrator But when trying to add to the project it just gives an error and the same goes with SVG I created with SVGator in short every single SVG gives me an error but using in bare HTML project its runs perfectly.

谁能指导我如何使用 SVG 做出反应

我得到的错误

  1. SVG 与 Adob​​e

     <style>.cls-1{fill:url(#a);}</style>

按照它的建议添加 {} 后给了我这个

Private names are only allowed in property accesses (`obj.#a`) or in `in` expressions 
 <style>.cls-1{{fill:url(#a)}}</style>
  1. 从网站下载SVG时出错

    编译有问题:

     ERROR [eslint] src\components\common\RegisterSvg.js Line 8:32256: Parsing error: Unexpected token (8:32256)

对于那些可能使用 SVG 出现此错误的人,请尝试导入 SVG 并将其用作图像,如果 SVG 是 SVG 是 SVG

import FormSvg from "./svg/newtest.svg
<img src={FormSvg} alt="svg"/>

if SVG has animation attached to it then add the SVG JavaScript in the useEffect and then use it as a normal SVG

useEffect(() => {
  // ... javascript goes here 
  // !function ... long code (<script>code from script</script>)
  }, []);
  return (
      // SVG part goes here
      <Svg/>
  )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM