我是react.js 和Javascript 的新手。我的工作是在图片上方添加一个下载按钮,点击后就会下载SVG格式的图片。我有一种方法有效,我将下载函数写入图像生成文件中,并调用该函数。但是只要我需要添加更多按钮,我发现图像svg文件在html页面里面。为什么我不能直接将 svg 内容保存到文件中。例如:按钮下载内容在我的react.js代码中,RankedBarchart渲染就是我想要的。有什么方法可以直接获取内容或下载内容。
<h2>
BMC values: sorted by {chartName}{' '}
<button onClick={plot_download_form} class="btn btn-primary">
Export plot
</button>
</h2>
<RankedBarchart
// the visualization function not affect the plot
// the selectedAxis is the main function to show tables,
// check the RankedBarchart file, selectedAxis part
data={plotData}
visualization={this.props.visualization}
selectedAxis={this.props.selectedAxis}
/>
Run Code Online (Sandbox Code Playgroud)