[英]How to get request body to be populated
我正在做一个get响应,在我的api / cmsview中,它没有得到我的Axios传递的对象。
class CmsView extends Component {
constructor(props) {
super(props)
this.state = {
cmsObj: [],
packageLid : props.location.state
}
var packageLid = this.props.location.state.packageLid
console.log(packageLid.PACKAGE_LID) //this gets populated with data
Axios.get('/api/cmsview', {packageLid})
.then((response) => {
this.setState({ cmsObj: response.data })
})
}
}
我的packageLid
确实填充了数据,但当我执行Axios时:
在我的cmsview.js中
router.get('/', (req, res, next) => {
console.log(req.body.packageLid.PACKAGE_LID)
}
我的req.body.packageLid
没有填充。 知道为什么吗? 它只输出“未定义”
您需要在componentDidMount方法中调用axios。
componentDidMount() {
var packageLid = this.props.location.state.packageLid
console.log(packageLid.PACKAGE_LID) //this gets populated with data
Axios.get('/api/cmsview', {packageLid})
.then((response) => {
this.setState({ cmsObj: response.data })
})
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.