【发布时间】:2016-10-28 23:48:03
【问题描述】:
我正在使用 Reactjs。我有一个表单,它将用一个 name 属性填充我的数据库 onSubmit。假设插入数据成功,我如何跳回到我的承诺中的登陆页面?我的着陆页网址是一个简单的“/”。或者我应该跳回到其他地方而不是在承诺中的登陆页面。
const React = require('react')
const axios = require('axios')
class AddNewRecordLabel extends React.Component {
constructor (props) {
super(props)
this.state = ({
artists: []
})
this.onSubmit = this.onSubmit.bind(this)
}
componentDidMount () {
axios.get('http://localhost:5050/recordLabels')
.then((res) => {
this.setState({
artists: res.data
})
})
}
onSubmit (e) {
e.preventDefault()
if (!this.refs.name.value) {
console.log('fill in the name input')
} else {
var object = {
name: this.refs.name.value
}
axios.post('http://localhost:5050/recordLabels', object)
.then((res) => {
//change here
})
}
}
render () {
return (
<div>
<h3>add new record label</h3>
<form onSubmit={this.onSubmit}>
<label>
<input type='text' ref='name' placeholder='name'/>
</label>
<br></br>
<button type='submit'> Add Record Label </button>
</form>
</div>
)
}
}
module.exports = AddNewRecordLabel
【问题讨论】:
标签: javascript reactjs navigation promise react-jsx