axios改同步
把axios的请求改为同步请求可以添加async: false选项,如下所示:
axios({
method: 'get',
url: 'http://example.com',
async: false,
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
需要注意的是,将请求改为同步请求会阻塞主线程,可能会导致页面卡顿或崩溃,不建议频繁使用。建议使用异步请求,通过回调或Promise等方式处理响应结果。
原文地址: https://www.cveoy.top/t/topic/f6vb 著作权归作者所有。请勿转载和采集!