React native 如何在react native中下载文件?
我在控制台中运行了这个命令React native 如何在react native中下载文件?,react-native,expo,React Native,Expo,我在控制台中运行了这个命令npm install react native fs--save 然后在我的onclick函数中使用此代码 _download = (downloadpath) => { // console.log(introduction); var RNFS = require('react-native-fs'); try { RNFS.downloadFile({ fromUrl: downloadpath,
npm install react native fs--save
然后在我的onclick函数中使用此代码
_download = (downloadpath) => {
// console.log(introduction);
var RNFS = require('react-native-fs');
try {
RNFS.downloadFile({
fromUrl: downloadpath,
toFile: `${RNFS.DocumentDirectoryPath}/test.zip`,
}).promise.then((r) => {
this.setState({ isDone: true })
});
} catch (error) {
console.log(error);
// Error saving data
}
}
但是它给了这个
很遗憾,RNFS与expo不兼容,因为它包装了本机库。你通常可以在家里查看