[英]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.