[英]Apiary API endpoint returning null data when called from web
我在Apiary中有一個模擬API,如果我用cURL或僅在瀏覽器中點擊我的端點,它會返回:
[
{
"id": 1,
"user_id": 1,
"status": "Review"
"name": "New York Songwriter",
"negotiable": true,
"description": "",
"created_at": "2015-02-09T02:29:58 +08:00",
"modified_at": "2015-02-17T05:30:17 +08:00"
},
{
"id": 2,
"user_id": 1,
"status": "Accepted"
"name": "Licensing Contract",
"negotiable": false,
"description": "Third party licensing agreement",
"created_at": "2015-02-09T02:29:58 +08:00",
"modified_at": "2015-02-17T05:30:17 +08:00"
}
]
我有一個作出反應的應用程序在那里我打這個端點與一個被稱為函數愛可信componentWillMount
:
componentWillMount() {
this.loadItems();
}
loadItems() {
var self = this;
axios({
url: ENDPOINT,
method: 'get',
responseType: 'json'
})
.then(function(r) {
console.log(r);
var d = r.data;
self.setState({
agreements: d
});
})
.catch(function(r) {
console.log(r);
});
}
console.log
我在響應中獲得狀態200,但data
為空。 我究竟做錯了什么?
感謝Mayank Shukla在評論中的回答。 關鍵是使用本機axios GET方法,如下所示:
axios.get(ENDPOINT)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
因為本機GET具有內置的所有屬性。在我的示例中,我沒有定義所有必需的屬性。
再次感謝Mayank!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.