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.aoyou183.cn/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. python 如何在 Matplotlib 中繪制垂直線2. ASP常用日期格式化函數(shù) FormatDate()3. 開發(fā)效率翻倍的Web API使用技巧4. 如何通過python實(shí)現(xiàn)IOU計(jì)算代碼實(shí)例5. bootstrap select2 動(dòng)態(tài)從后臺(tái)Ajax動(dòng)態(tài)獲取數(shù)據(jù)的代碼6. CSS3中Transition屬性詳解以及示例分享7. js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼8. Python 操作 MySQL數(shù)據(jù)庫(kù)9. vue使用moment如何將時(shí)間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時(shí)間格式10. python中@contextmanager實(shí)例用法
