vue實(shí)現(xiàn)實(shí)時(shí)上傳文件進(jìn)度條
本文實(shí)例為大家分享了vue實(shí)時(shí)上傳文件進(jìn)度條,供大家參考,具體內(nèi)容如下

//上傳文件組件 <el-upload ? ? ? ? action ? ? ? ? :show-file-list="false" ? ? ? ? :before-upload="uploadFile" > ? ? ? <el-button type="primary" :disabled="progressFlag">上傳數(shù)據(jù)</el-button> </el-upload> //進(jìn)度條組件 <div :class="progressFlag?'progress':'progress1'"> ? ? ? ? <el-progress ? ? ? ? ? ? ? ? id="progress" ? ? ? ? ? ? ? ? ?type="circle" ? ? ? ? ? ? ? ? ?:percentage="percent" ? ? ? ? ? ? ? ? ?:stroke-width="8" ? ? ? ? ? ? ? ? ? :width="100" ? ? ? ? ? ? ? ? ? :show-text="true" ? ? ? ? ? ? ? ? ? stroke-linecap="round" ? ? ? ? ? ? ? ? ? :format="progressFormat" ? ? ? ? ></el-progress> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? </div>
data() {
?? ?return {
?? ??? ?percent:0,
?? ??? ?progressFlag:false,
?? ??? ?deg:135,
?? ??? ?status:this.percent<100?"":"success",//進(jìn)度條組件加上狀態(tài)后不顯示文字
?? ??? ?color:[
?? ??? ??? ?{color:"#fdfdfd",percentage:99},
?? ??? ??? ?{color:"#ccccc",percentage:100},
?? ??? ?]
?? ?}
}methods:{
async uploadFile(file){
? ? ? ? //:on-progress="uploadFile"上傳時(shí)會(huì)多次調(diào)用,由于是本地,間隔較大
? ? ? ? let reg = /(?<=\.)[a-z]+$/g
? ? ? ? let fileType = file.name.match(reg)+""
? ? ? ? let typeArr = ["xls","xlsx","csv"]
? ? ? ? if(!typeArr.includes(fileType)){
? ? ? ? ? ? this.$message.warning("上傳文件格式錯(cuò)誤!")
? ? ? ? ? ? return?
? ? ? ? }
? ? ? ? let formData = new FormData()
? ? ? ? formData.append('file',file)
? ? ? ? // realtimeUploadLocal({
? ? ? ? // ? ? file:formData,
? ? ? ? // ? ? uid:this.$store.state.userInfo.user.uid,
? ? ? ? // })
? ? ? ? this.progressFlag = true
? ? ? ? await realtimeUpload(formData,this).then((res)=>{
? ? ? ? ? ? if(res.code == "0"){
? ? ? ? ? ? ? ? this.$message.success(res.data)
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? this.$message.warning(res.data)
? ? ? ? ? ? }
? ? ? ? })
? ? ? ? setTimeout(()=>{
? ? ? ? ? ? this.progressFlag = false
? ? ? ? ? ? // this.rotateFn(0)
? ? ? ? ? ? this.percent = 0
? ? ? ? },1000)
? ? },
progressFormat(percentage){
? ? ? ? return percentage<100?"已上傳("+percentage+"%)":"上傳完成"
?}
}<style scoped lang="less">
.progress1{ display:none;}
.progress{
? ? ? ? display: flex;
? ? ? ? width: 80px;
? ? ? ? height: 80px;
? ? ? ? position: absolute;
? ? ? ? top: 40px;
? ? ? ? left: 50%;
? ? ? ? transform: translate(-50%, 0);
? ? ? ? background-color: transparent;
}
</style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue Router動(dòng)態(tài)路由使用方法總結(jié)
這篇文章主要介紹了Vue Router動(dòng)態(tài)路由使用方法總結(jié),需要的朋友可以參考下2023-10-10
element-ui 關(guān)于獲取select 的label值方法
今天小編就為大家分享一篇element-ui 關(guān)于獲取select 的label值方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
VUE table表格動(dòng)態(tài)添加一列數(shù)據(jù),新增的這些數(shù)據(jù)不可以編輯(v-model綁定的數(shù)據(jù)不能實(shí)時(shí)更新)
這篇文章主要介紹了VUE table表格動(dòng)態(tài)添加一列數(shù)據(jù),新增的這些數(shù)據(jù)不可以編輯(v-model綁定的數(shù)據(jù)不能實(shí)時(shí)更新),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2020-04-04
vue中異步數(shù)據(jù)獲取方式(確保數(shù)據(jù)被獲取)
這篇文章主要介紹了vue中異步數(shù)據(jù)獲取方式(確保數(shù)據(jù)被獲取),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01
vue3+Ts使用pinia方式(vue-lic搭建項(xiàng)目)
文章介紹了如何在Vue 3項(xiàng)目中使用Pinia進(jìn)行狀態(tài)管理,主要內(nèi)容包括安裝Pinia、初始化、在main.ts中注冊(cè)和使用,以及在.vue的setup中使用state,文章還提到getters和actions的使用可以參考官方文檔,總結(jié)部分表達(dá)了作者希望得到大家支持的意愿2025-01-01
vue2.0 根據(jù)狀態(tài)值進(jìn)行樣式的改變展示方法
下面小編就為大家分享一篇vue2.0 根據(jù)狀態(tài)值進(jìn)行樣式的改變展示方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
vue深度監(jiān)聽(tīng)(監(jiān)聽(tīng)對(duì)象和數(shù)組的改變)與立即執(zhí)行監(jiān)聽(tīng)實(shí)例
這篇文章主要介紹了vue深度監(jiān)聽(tīng)(監(jiān)聽(tīng)對(duì)象和數(shù)組的改變)與立即執(zhí)行監(jiān)聽(tīng)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09

