【发布时间】:2018-10-21 06:05:24
【问题描述】:
这是我得到的错误:
calls to `require` expect exactly 1 string literal argument, but this was found: `require(image.path)`
这是我的代码:
class NewPost extends Component {
constructor(props) {
super(props);
this.state = {
uploadPicture: null
}
}
openGallery() {
ImagePicker.openPicker({
width: 600,
height: 400,
cropping: true
}).then(image => {
uploadPictureVar = require(image.path);
this.setState({ uploadPicture: uploadPictureVar });
});
}
}
render() {
return (
<View style={styles.imageContainer}>
{this.state.uploadPicture ?
<Image
style={styles.imagePost}
source={this.state.uploadPicture}
/>
: null}
</View>
)
}
我看到这个问题require() must have a single string literal argument React Native 但是我没有字符串可以放入我上传图片时得到的要求中。
【问题讨论】:
标签: reactjs react-native