5-3 RN 的异步请求与封装 报错
来源:
poooocket
2016-10-25
一、代码如下
_fetchData(){
request.get('http://rap.taobao.org/mockjs/8157/api/creations?accessToken=abcd')
.then((data) => {
if(data.success){
this.setState({
dataSource:this.state.dataSource.cloneWithRows(data.data)
})
}
})
.catch((error) => {
console.warn(error);
});
},
正常运行。
二、如果修改请求地址 用
request.get(config.api.base+config.api.creations,{accessToken:'abcde'}) 代替
如下代码:
_fetchData(){
request.get(config.api.base+config.api.creations,{accessToken:'abcde'})
.then((data) => {
if(data.success){
this.setState({
dataSource:this.state.dataSource.cloneWithRows(data.data)
})
}
})
.catch((error) => {
console.warn(error);
});
},
就会报错:
ExceptionsManager.js:82 The RCTURLRequestHandlers <RCTFileRequestHandler: 0x608004811a50> and <RCTImageStoreManager: 0x60800382b760> both reported that they can handle the request <NSMutableURLRequest: 0x608002a16280> { URL: %20http://rap.taobao.org/mockjs/8157/api/creations?accessToken=abcde }, and have equal priority (0). This could result in non-deterministic behavior.
TypeError: Network request failed(…)
1回答
-
poooocket
提问者
2016-10-25
module.exports = {
header:{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
},
api:{
base:' http://rap.taobao.org/mockjs/8157/',
creations:'api/creations',
}
}
base: 请求地址前面有空格,所以请求地址出错,
10
相似问题