vue结合axios实现下载进度条
封装的post请求config是重点export function post(url, data = {},config = {}) {return new Promise((resolve, reject) => {axios.post(url, data,config).then(response => {if (response...
·
封装的post请求
config
是重点
export function post(url, data = {},config = {}) {
return new Promise((resolve, reject) => {
axios.post(url, data,config)
.then(response => {
if (response) {
resolve(response.data);
} else {
router.push({
path: '/'
})
}
}, err => {
// reject(err);
})
})
}
代码中实现(ui样式可以随便参考一下其他的)
$nextTick
实现dom的异步刷新,具体见这个链接 简单理解Vue中的nextTick
post("/merchant/v1/account/queryMerchantAccountDetail", data, {
onDownloadProgress(a) {
var percent = parseInt(100 * (a.loaded / a.total));
_this.$nextTick(() => {
_this.progressNum = percent;
});
}
}).then(response => {
if (response.data) {
this.excelData = response.data.results[0].list;
this.outExe5();
}
});
更多推荐
已为社区贡献1条内容
所有评论(0)