Jestem nowy, aby zareagować js. Chcę przesłać zdjęcie asynchronicznie z reagują js Załóżmy, że mam ten kodReakcja na przesyłanie pliku js
var FormBox = React.createClass({
getInitialState: function() {
return {
photo: []
}
},
pressButton: function() {
var data = new FormData();
data.append("photo", this.state.photo);
// is this the correct way to get file data?
},
getPhoto: function (e) {
this.setState({
photo: e.target.files[0]
})
},
render: function() {
return (
<form action='.' enctype="multipart/form-data">
<input type='file' onChange={this.getPhoto}/>
<button onClick={this.pressButton}> Get it </button>
</form>
)
}
})
ReactDOM.render(<FormBox />, document.getElementById('root'))
Każda odpowiedź będzie mile widziana!
Należy rozważyć dodanie wyjaśnienie odpowiedź jesteś proponowanie. –