当前位置:网站首页>Make a file upload progress bar
Make a file upload progress bar
2022-07-29 19:02:00 【weixin_46787337】
先看原生js怎么做
关键点: 监听请求的upload.onprogress事件
// 发请求
const ajax = (url: string, data: FormData) => {
return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();
request.open('POST', url);
request.onreadystatechange = () => {
if (document.readyState === 'complete' && request.status === 200) {
resolve(request.response);
} else {
reject(new Error('上传失败'));
}
};
request.upload.onprogress = (e: ProgressEvent) => {
//Here you can get the information of the progress bar
console.log(`${
e.loaded/ e.total*100 ||0}%`)
};
request.send(data);
});
};
axios做进度条
The point is that sending a request is a configurationonUploadProgress:
async uploadVideo () {
const {
uploadFile} = this
if(uploadFile){
let param = new FormData() //创建form对象,私有,无法直接获取,只能通过getto see the elements
param.append('file',uploadFile)
let config = {
headers:{
'Content-Type':'multipart/form-data',
},
transformRequest: [function (data) {
return data
}],
onUploadProgress: progressEvent => {
let persent = (progressEvent.loaded / progressEvent.total * 100 | 0) //上传进度百分比
console.log(persent)
},
}
axios.post('http://xxxxxxxx/video/upload',param,config) //Address to write your own interface
.then(response=>{
var result = response.data
if(result.status == 0){
console.log(result)
}else{
this.$message({
message: '上传失败',
type: 'error',
duration:'1000'
});
}
}).catch(err => {
console.log(err)
})
}
},
边栏推荐
- MySql解决GROUP BY出现的问题
- AMD收购赛灵思已获两家公司股东同意
- 【深度学习】使用yolov5对数据进行预标注
- Thread、Runnable、Callable、Future ... 的关系?
- [memory] grandma's song
- 数据监控体系是什么?该怎么搭建?
- 数字化来势汹汹,低代码起势,JNPF助力企业定制专属BIM
- [Deep Learning] YOLO to VOC VOC to YOLO
- One's deceased father grind English vocabulary training camp Day 17 】 -- espresso, ultimate, gradually, detect, dimension
- turtle简单教程文档
猜你喜欢

centos7服务器安全策略

一文了解信创背景下 SAN 存储转型路线

transformer通俗理解

实现get/post请求调用第三方接口

【7.23-7.29】博客精彩回顾

分批数据遍历的优化

Virtink:更轻量的 Kubernetes 原生虚拟化管理引擎

Xatlas source code parsing (7)

The structure of the earth's over 200 million proteins is fully predicted, and AlphaFold detonates the "protein universe"

Zadig 环境负载均衡:0 人工干预,极速部署
随机推荐
如何实时计算日累计逐单资金流
centos7 server security policy
三轮电摩专用之48V动力锂电池组-产品规格书
最近很郁闷
【QT】Qt获取前几天/后几天的时间
KubeMeet 报名 | 「边缘原生」线上技术沙龙完整议程公布!
今年一季度全球PC出货量同比增长32%,创21年来最快增速
The problem that crontab executes scheduled tasks and reports errors
新王加冕还是动物乐园?7大顶级蓝筹NFT项目详解
593. 有效的正方形 改善丑陋的代码
Zigbee组网控制流程
One's deceased father grind English vocabulary training camp Day 】 16 - bankrupt, remain, regulate, the construct and reflect
带你入门云开发实践总结篇
500强企业如何提升研发效能?来看看行业专家怎么说
UG安装出现Server Start Failed. The Server May Already Be Running!!解决方法
AMD收购赛灵思已获两家公司股东同意
【码蹄集新手村600题】给定一个整数n,求floor(n/x)=y 中 x,y 的所有值
【码蹄集新手村600题】求所给数据的平方根
公司无线规划设计及实施SOP
EasyNVR更新版本至(V5.3.0)后页面不显示通道配置该如何解决?