vue實(shí)現(xiàn)簡(jiǎn)單圖片上傳
本文實(shí)例為大家分享了vue實(shí)現(xiàn)簡(jiǎn)單圖片上傳的具體代碼,供大家參考,具體內(nèi)容如下
功能
- 實(shí)現(xiàn)圖片上傳
- 顯示進(jìn)度條
<template>
<div class="about">
<div>
<div>
<img :src="'https://www.xxx.com'+item" alt="" v-for="item in pics" >
</div>
<label><input type="file" ref="file" @change="up()">+<span class="label" :style="{width:pre+'%'}"></span></label>
</div>
</div>
</template>
<style scoped="scoped">
label{
width: 100px;
height: 100px;
display: inline-block;
overflow: hidden;
background-color: #CCCCCC;
color: #FFFFFF;
font-size: 48px;
text-align: center;
line-height: 100px;
position: relative;
}
input{display: none;}
.label{
position: absolute;
display: inline-block;
bottom: 0;
left: 0;
height: 2px;
width: 0%;
background-color: #FFA500;
}
</style>
<script>
export default{
name: 'About',
data(){
return{
pics:[],
pre:0,
}
},
methods:{
up(){
var that=this;
var file=this.$refs.file.files[0];
var data=new FormData();
data.append("file",file);
this.$http.post("https://www.xxx.com/ajax/file.php",data,{
onUploadProgress:e=>{
this.pre=e.loaded/e.total*100
console.log("+++",e)
}
})
.then(res=>{
if(res.data.error==0){
this.pics.push(res.data.pic)
console.log("----",res)
}
})
.catch(err=>{
console.log(err)
})
this.pre=0
},
}
}
</script>

關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue實(shí)現(xiàn)圖片上傳預(yù)覽功能
- vue項(xiàng)目實(shí)現(xiàn)圖片上傳功能
- Vue移動(dòng)端實(shí)現(xiàn)圖片上傳及超過1M壓縮上傳
- vue實(shí)現(xiàn)移動(dòng)端圖片上傳功能
- Vue formData實(shí)現(xiàn)圖片上傳
- vue實(shí)現(xiàn)axios圖片上傳功能
- vue+element-ui+axios實(shí)現(xiàn)圖片上傳
- Vue + Element UI圖片上傳控件使用詳解
- vue+elementUI實(shí)現(xiàn)圖片上傳功能
- vue+elementUi圖片上傳組件使用詳解
相關(guān)文章
前端vue-cli項(xiàng)目中使用img圖片和background背景圖的幾種方法
這篇文章主要介紹了前端vue-cli項(xiàng)目中使用img圖片和background背景圖的幾種方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
Vue實(shí)現(xiàn)input寬度隨文字長(zhǎng)度自適應(yīng)操作
這篇文章主要介紹了Vue實(shí)現(xiàn)input寬度隨文字長(zhǎng)度自適應(yīng)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07
Vue實(shí)現(xiàn)table上下移動(dòng)功能示例
這篇文章主要介紹了Vue實(shí)現(xiàn)table上下移動(dòng)功能,結(jié)合實(shí)例形式分析了vue.js針對(duì)table表格元素動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-02-02
vue.js實(shí)現(xiàn)的全選與全不選功能示例【基于elementui】
這篇文章主要介紹了vue.js實(shí)現(xiàn)的全選與全不選功能,結(jié)合實(shí)例形式分析了vue.js基于elementui實(shí)現(xiàn)全選與全不選功能的相關(guān)頁(yè)面渲染、初始化數(shù)據(jù)及功能函數(shù)等相關(guān)操作技巧,需要的朋友可以參考下2018-12-12
vue?模板循環(huán)繪制多行上傳文件功能實(shí)現(xiàn)
這篇文章主要為大家介紹了vue?模板循環(huán)繪制多行上傳文件功能實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07
Vue中watch監(jiān)聽第一次不觸發(fā)、深度監(jiān)聽問題
這篇文章主要介紹了Vue中watch監(jiān)聽第一次不觸發(fā)、深度監(jiān)聽問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
簡(jiǎn)單聊聊vue2.x的$attrs和$listeners
vue組件之間的通信方式有很多種,props/emit,event bus,vuex,provide/inject等,還有一種通信方式就是$attrs和$listeners,下面這篇文章主要給大家介紹了關(guān)于vue2.x中$attrs和$listeners的相關(guān)資料,需要的朋友可以參考下2022-03-03

