我的應用程序應根據路線呈現大約30000個svg元素。 如果路線類似www.myapp.com/svg-data/person,它應該呈現person.svg。作爲反應組件加載svg dinamically
稍後(相同的路徑),可以修改此svg:添加背景顏色,一些文本或某些預定義的圖層。 我想我應該加載svg作爲反應組件。我正在看圖書館https://github.com/boopathi/react-svg-loader,但我不認爲它真的適合我的目的。
我的最後一個問題是關於獲取SVG數據作爲串並使其返回除其他事物的SVG一個組件內...
我應該建立一個通用組件,呈現自帶作爲參數任何SVG :
componentDidMount() {
if (this.props.params.searchText) {
this.props.requestSVG(this.props.params.searchText)
}
}
componentWillReceiveProps(nextProps) {
if (this.props.params.searchText !== nextProps.params.searchText) {
this.props.requestSVG(nextProps.params.searchText)
}
}
這部分將呈現類似:
render() {
const {svgData, textForSVGData} = this.props
let svgText=null
if (textForSVGData) {
svgText= <text x='250' y='150' font-size='55'> {textForSVGData} </text>
}
return (
<svg>
{this.props.svgData}
{svgText}
</svg>
)
}
根據道具應該添加文本,或者在需要的任何其他東西。我想念什麼?這是做這件事的好方法嗎?
我正在使用webpack。只是不知道如何將30000個svg組件集成到我的js代碼中! – user2670996