【发布时间】:2017-06-05 08:45:01
【问题描述】:
我试图在我的 Image 组件中要求使用 react-native-fetch-blob 下载的图像,但是当我给它图像路径时,它一直说我 « Unknow named module: '/Users/.../Library/ ……'
要求图像存储在本地目录中的正确方法是什么?
let imagePath = null
RNFetchBlob
.config({
fileCache : true
})
.fetch('GET', uri)
// the image is now dowloaded to device's storage
.then((resp) => {
// the image path you can use it directly with Image component
imagePath = resp.path()
this.setState({ uri: require(imagePath) })
try {
AsyncStorage.setItem(`${this.props.uri}`, imagePath);
} catch (error) {
console.log(error)
}
})
我的渲染方法:
render() {
return(
<Image style={this.props.style} source={this.state.uri} />
)
}
问题不是因为我将变量设置为源,因为当我在下载后放置类似 this.setState({ uri: require('../images/test.jpg') }) 的内容时它正在工作。
【问题讨论】:
标签: image react-native require react-native-fetch-blob