react download csv 功能
写一个download的方法:
const handleDownload = () => {
const fileUrl = '/path/to/your/file.csv'; // 替换为你的 CSV 文件的路径
window.open(fileUrl);
};写一个函数:
function App() {
return (
<div>
{/* 其他组件 */}
<button onClick={handleDownload}>下载 CSV 文件</button>
</div>
);
}
'/path/to/your/file.csv'可以在import的时候和其他一起使用, 例如:
import chinaPopulationData from './china_population.csv'然后可以:
const fileUrl = chinaPopulationData;