componentDidMount() { const { type } = searchToObj(window.location.hash); const url = parseInt(type, 10) === 1 ? "server_callback" : "subscribe_callback"; this.setState(() => ({ loading: true })); http .get(url, null) .then(res => { if (res.code === 0) { const { list: { fans_rank } } = res; if (fans_rank.length === 0) { this.setState(() => ({ loading: false, noData: true })); } else { this.setState(() => ({ loading: false, data: fans_rank })); } } else { this.setState( () => ({ loading: false, netBad: true }), () => Toast.info(res.message, 2) ); } }) .catch(err => { this.setState( () => ({ loading: false, netBad: true }), () => Toast.fail("网络出错,请稍后再试!", 2) ); }); }
() => { const offset = isNewStart ? 0 : listData.length; http .get({ ...dataParam, offset, limit }) .then(response => { if (isNewStart) Toast.hide(); // 这里的判断条件根据具体的接口情况而调整 const { errcode, message } = response if (parseInt(errcode, 10) === 0) { const data = response[dataName]; const dataNoMore = data ? data.length < limit : true; // 记录滚动条位置 if (this.isCancle) return const h = listenEle.scrollTop; this.setState( preState => ({ listData: isNewStart ? data : preState.listData.concat(data || []), dataNoMore, isLoading: false }), () => { listenEle.scrollTop = h; if (loadSuccess) loadSuccess(); } ); } else if (parseInt(errcode, 10) === 402) { // token无效的特殊状态,需要特殊处理 Toast.info(message || "token无效,请重新登陆") common.delCookie("token") } else if (errcode > 0) { Toast.info(message || "请求出错,请稍后重试!") } }) .catch(err => { this.setState(() => ({ netBad: true })); console.info(err); }); }
componentDidMount() { http.get("applications").then(response => { console.log(response, "rrr"); }); }