Ama*_*apa 6 reactjs material-ui
<Input
id="image"
type="file"
accept="image/*"
onChange={(event) =>
getBase64(event.target.files[0])
.then((file) => this.setState({ image: file })
)}
/>
Run Code Online (Sandbox Code Playgroud)
但它也接受其他文件,我应该更改什么以使其仅接受图像?
要设置accept属性,<Input />您需要inputProps像这样使用
<Input type="file" inputProps={{ accept: 'image/*' }} />
Run Code Online (Sandbox Code Playgroud)
编辑 几个月后查看这个并阅读@Aprillions评论我认为澄清这是Material-UI而不是纯粹的React会很好
| 归档时间: |
|
| 查看次数: |
20727 次 |
| 最近记录: |