在React中,你可以使用fetch()函数或axios库来读取文件内容。
使用fetch()函数:
fetch('path/to/file.txt') .then(response => response.text()) .then(data => { // 处理文件内容 console.log(data); }) .catch(error => { // 处理错误 console.log(error); });使用axios库:
axios.get('path/to/file.txt') .then(response => { // 处理文件内容 console.log(response.data); }) .catch(error => { // 处理错误 console.log(error); });无论使用fetch()函数还是axios库,都需要在你的React组件中引入它们。

