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.hdgsjgj.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)擊專(zhuān)題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP編碼必備的8條原則2. 使用css實(shí)現(xiàn)全兼容tooltip提示框3. 一文帶你搞懂JavaScript中的進(jìn)制與進(jìn)制轉(zhuǎn)換4. 匹配模式 - XSL教程 - 45. 詳解JS前端使用迭代器和生成器原理及示例6. 得到XML文檔大小的方法7. 詳解CSS偽元素的妙用單標(biāo)簽之美8. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)9. ASP基礎(chǔ)知識(shí)Command對(duì)象講解10. 怎樣才能用js生成xmldom對(duì)象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?
