代码如下:
const onFinish = (values={}) => {
request.get(url).then(data =>{
})
console.log("执行成功")
}
我如何根据data的值,让console语句不执行。因为是第一次做前端需求,感觉很懵。求哥哥们给个思路
不知道是否能帮到你
componentDidMount() {
// GET request using fetch with error handling
fetch('https://api.npms.io/v2/invalid-url')
.then(async response => {
const data = await response.json();
// check for error response
if (!response.ok) {
// get error message from body or default to response statusText
const error = (data && data.message) || response.statusText;
return Promise.reject(error);
}
this.setState({ totalReactPackages: data.total })
})
.catch(error => {
this.setState({ errorMessage: error.toString() });
console.error('There was an error!', error);
});
}
async isURLExpired(url) {
if (!this._maxAgeSeconds) {
{
throw new WorkboxError_js.WorkboxError(`expired-test-without-max-age`, {
methodName: 'isURLExpired',
paramName: 'maxAgeSeconds'
});
}
} else {
const timestamp = await this._timestampModel.getTimestamp(url);
const expireOlderThan = Date.now() - this._maxAgeSeconds * 1000;
return timestamp < expireOlderThan;
}
}
像你这种情况在公司直接套模板就行,使用async await加上if判断一下,再return结束就可以啦。一般接口比较多的话,批量套模板即可,希望可以帮助你!