猿问

react之ant design mobile如何只能上传一张图片

ant design mobile 上的图片上传,如何只显示一个上传选择器啊,一用它,就出来四个啊,

补称:`<ImagePicker

   files={files}
   onChange={this.onChange}
   onImageClick={(index, fs) => console.log(index, fs)}
   selectable={files.length < 5}
   accept="image/gif,image/jpeg,image/jpg,image/png"
    />`

就是我只要左边那个带十字架的那个,并且让它居中,一次只能上传一张,可预览

求解


智慧大石
浏览 1322回答 1
1回答

慕少森

这样不就好了,外边的样式你自己搞吧multiple={true}是说你点上传框之后,一次性可以选一张还是多张图,false就只能一张张的上传class ImagePickerExample extends React.Component {&nbsp; state = {&nbsp; &nbsp; files: [],&nbsp; }&nbsp; onChange = (files, type, index) => {&nbsp; &nbsp; console.log(files, type, index);&nbsp; &nbsp; this.setState({&nbsp; &nbsp; &nbsp; files,&nbsp; &nbsp; });&nbsp; }&nbsp; render() {&nbsp; &nbsp; const { files } = this.state;&nbsp; &nbsp; return (&nbsp; &nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; &nbsp; <ImagePicker&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; files={files}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onChange={this.onChange}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onImageClick={(index, fs) => console.log(index, fs)}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; selectable={files.length < 1}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; accept="image/gif,image/jpeg,image/jpg,image/png"&nbsp; &nbsp; &nbsp; &nbsp; />&nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; );&nbsp; }}ReactDOM.render(<ImagePickerExample />, mountNode);
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答