vue實(shí)現(xiàn)簡單圖片上傳
本文實(shí)例為大家分享了vue實(shí)現(xià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組件的教程,請大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部內(nèi)容,希望對大家的學(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)文章
vuex直接修改state、commit和dispatch修改state的用法及區(qū)別說明
這篇文章主要介紹了vuex直接修改state、commit和dispatch修改state的用法及區(qū)別說明,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08在vue中通過render函數(shù)給子組件設(shè)置ref操作
這篇文章主要介紹了在vue中通過render函數(shù)給子組件設(shè)置ref操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11Vue項(xiàng)目查看當(dāng)前使用的elementUI版本的方法
今天小編就為大家分享一篇Vue項(xiàng)目查看當(dāng)前使用的elementUI版本的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09解決vue-cli項(xiàng)目webpack打包后iconfont文件路徑的問題
今天小編就為大家分享一篇解決vue-cli項(xiàng)目webpack打包后iconfont文件路徑的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09