damianstasik / vite-svg

Use SVG files as Vue components with Vite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to add props to svg tags by component ?

arleyGuoLei opened this issue · comments

commented
import SvgIcon from './alarm.svg'

const comp => () => {
  return (<SvgIcon width={32} height={32} />)
}

Currently does not support props?eg: widthheightsizecolor?


svgProps option is static config ...

commented
      reactSvgPlugin({
        // 使用 svg 组件方案
        defaultExport: 'component',
        svgo: false,

        // 配置为 start,生成的 svg 标签才会传递 props变量
        expandProps: 'start',
        // 可以传入变量,通过 svg标签支持 size、width、height、fill 属性
        svgProps: {
          height: '{props.size || props.height}',
          width: '{props.size || props.width}',
          fill: '{props.fill || "currentColor"}'
        }
      })

解决了 ~