react20180419

1.在一个store文件里,同一个类的不同@action可以实现传值取值,@action A产生值之后将它放到@observable,然后在@action B里使用this.XXX.slice()即可获得,记得加.slice()转成普通数组队形,参考链接地址:http://cn.mobx.js.org/refguide/array.html

@observable mapping_station_data = [];
var station_datas = this.mapping_station_data.stations.slice();
虽然在控制台看到的数组是有999个元素组成这样子的,但一换到数组匹配之后就变成正常额的数组的
var outSite =  station_datas[k].name;

2.

react fetch请求方法,亲测过的写法如下:
get请求的时候
fetch('MYURL').
then(res=>res.json()).
then(json=>dispatch(myActionName(json))).
catch(err=>dispatch(myErrActionName(err)));

POST请求的时候
fetch(‘URL’,
{
method:'POST',
headers: { 
'Accept': 'application/json',
'Content-Type': 'application/json' 
},
body:JSON.stringify({'data':json})
}
)
.then(res => res.json())
.then(json =>dispatch(receivePosts(json)))
.catch(error=>dispatch(requestExceptions(error)));
JSON.stringify这个很重要,否则我们的数据无法被识别为json会很痛苦。希望对您的开发有帮助


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值