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='http://www.piao2010.com/bcjs/’https://www.xxx.com’+item' alt='' v-for='item in pics' > </div> <label><input type='file' ref='file' @change='up()'>+<span :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í)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 阿里前端開發(fā)中的規(guī)范要求2. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案3. css進(jìn)階學(xué)習(xí) 選擇符4. UDDI FAQs5. XML入門的常見問(wèn)題(一)6. html小技巧之td,div標(biāo)簽里內(nèi)容不換行7. PHP字符串前后字符或空格刪除方法介紹8. XML入門精解之結(jié)構(gòu)與語(yǔ)法9. Echarts通過(guò)dataset數(shù)據(jù)集實(shí)現(xiàn)創(chuàng)建單軸散點(diǎn)圖10. 概述IE和SQL2k開發(fā)一個(gè)XML聊天程序
