vue實(shí)現(xiàn)element上傳多張圖片瀏覽刪除功能
vue原生實(shí)現(xiàn)element上傳多張圖片瀏覽刪除
<div class="updata-component" style="width:100%;"> <div class="demo-upload-box clearfix"> <div class="demo-upload-image-box" v-if="imageUrlArr && imageUrlArr.length"> <div class="demo-upload-image" v-for="(item,index) in imageUrlArr" :key="index"> <img :src="item"> <div class="demo-upload-box-cover"> <!-- 點(diǎn)擊刪除 --> <i class="el-icon-delete" style="position: absolute;left: 30%;top: 80%;z-index:2;color:#fff;" @click="handleRemoves(index)"></i> <!-- 點(diǎn)擊瀏覽 --> <i class="el-icon-zoom-in" @click="handleView(index)" style="position: absolute;left: 56%;top: 80%;z-index:2;color:#fff;"></i> </div> </div> </div> <div class="demo-upload-btn" v-show="isshowlng"> <input ref="uploadInput" type="file" class="file" @change="handleSuccess"> <i slot="default" class="el-icon-plus"></i> <input type="button" class="btn" @click="clickFile" /> </div> </div> <!-- 查看大圖 --> <el-dialog :visible.sync="dialogVisible" :modal-append-to-body="false"> <img width="100%" :src="bigPicSrc" alt=""> </el-dialog> </div> data(){ return{ bigPicSrc: '', imageUrlArr: [],//頁面展示url數(shù)組 filesData: [],//file數(shù)組 isshowlng:true,//判斷上傳圖片按鈕是否顯示 } }, methods:{ // 文件上傳接收 handleSuccess (e) { console.log('------',e) console.log('imgs.lenght',this.imgs.length) var lng=6-this.imgs.length console.log('lng',lng) let file = e.target for (let i = 0; i < file.files.length; i++) { this.imageUrlArr.push(window.URL.createObjectURL(file.files.item(i))) this.filesData.push(file.files[i]) } console.log('this.filesData',this.filesData) console.log('this.filesData.length',this.filesData.length) if(this.filesData.length>=lng){ this.isshowlng=false }else{ this.isshowlng=true } }, clickFile () { const input = this.$refs.uploadInput input.click() }, // 刪除上傳的案例圖 handleRemoves (index) { console.log('刪除') this.imageUrlArr.splice(index, 1) this.filesData.splice(index, 1) var lng=6;//限制最多上傳6張 if(this.filesData.length>=lng){ this.isshowlng=false }else{ this.isshowlng=true } this.$forceUpdate() }, // 查看大圖 handleView (index) { console.log('查看大圖') this.dialogVisible=true this.bigPicSrc = this.imageUrlArr[index] }, } <style> /* ------------------------- */ .demo-upload-image-box{ height: 150px; /* width: 120px; */ /* padding: 10px; */ float: left; } .demo-upload-btn{ width: 115px; height: 115px; background-color: #fbfdff; border: 1px dashed #c0ccda; border-radius: 6px; text-align: center; position: relative; float: left; } .demo-upload-image{ width: 117px; height: 117px; margin-right: 5px; display: inline-block; position: relative; } .demo-upload-image img{ width: 115px; height: 115px; } .big-pic{ position: fixed; left: 40%; top: 20%; } .big-pic img{ width: 400px; height: 300px; } .file { width: 115px; height: 115px; display: none; } .btn { position: absolute; top: 0; left: 0; width: 60px; height: 60px; background: rgba(0, 0, 0, 0); z-index: 10; border: none; cursor: pointer; } .demo-upload-btn .el-icon-plus{ line-height: 110px; font-size: 16px; /* position: absolute; left: 40px; */ } .el-icon-plus:before{ font-size: 30px; color: #8c939d; } .demo-upload-box-cover{ background: rgba(0,0,0,0.3); width: 100%; height: 100%; position:absolute; left:0; top:0; border-radius:5px; } </style>
到此這篇關(guān)于vue實(shí)現(xiàn)element上傳多張圖片瀏覽刪除功能的文章就介紹到這了,更多相關(guān)vue element上傳多張圖片內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue?elementui?實(shí)現(xiàn)圖片上傳后拖拽排序功能示例代碼
- Vue3?+?elementplus實(shí)現(xiàn)表單驗(yàn)證+上傳圖片+?防止表單重復(fù)提交功能
- vue+elementUI實(shí)現(xiàn)多文件上傳與預(yù)覽功能實(shí)戰(zhàn)記錄(word/PDF/圖片/docx/doc/xlxs/txt)
- 使用vue和element-ui上傳圖片及視頻文件方式
- vue使用element實(shí)現(xiàn)上傳圖片和修改圖片功能
- Vue+elementUI實(shí)現(xiàn)多圖片上傳與回顯功能(含回顯后繼續(xù)上傳或刪除)
相關(guān)文章
uniapp項(xiàng)目國際化標(biāo)準(zhǔn)的配置與實(shí)現(xiàn)
UniApp是一種基于Vue.js的跨平臺開發(fā)框架,可以快速地開發(fā)同時(shí)運(yùn)行在多個平臺的應(yīng)用程序,這篇文章主要介紹了uniapp項(xiàng)目國際化標(biāo)準(zhǔn)的配置與實(shí)現(xiàn),需要的朋友可以參考下2023-11-11vue-cli3配置多項(xiàng)目并按項(xiàng)目分別實(shí)現(xiàn)打包
這篇文章主要介紹了vue-cli3配置多項(xiàng)目并按項(xiàng)目分別實(shí)現(xiàn)打包方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01Vue3使用vue-router如何實(shí)現(xiàn)路由跳轉(zhuǎn)與參數(shù)獲取
這篇文章主要介紹了Vue3使用vue-router如何實(shí)現(xiàn)路由跳轉(zhuǎn)與參數(shù)獲取,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03vue-cli3 karma單元測試的實(shí)現(xiàn)
這篇文章主要介紹了vue-cli3 karma單元測試的實(shí)現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01解決vue3項(xiàng)目打包后部署后某些靜態(tài)資源圖片不加載問題
這篇文章主要給大家介紹了如何解決vue3項(xiàng)目打包后部署后某些靜態(tài)資源圖片不加載問題,文中通過圖文結(jié)合的方式講解的非常詳細(xì),有需要的朋友可以參考下2024-05-05vue自定義實(shí)例化modal彈窗功能的實(shí)現(xiàn)
這篇文章主要介紹了vue自定義實(shí)例化modal彈窗,Vue.extend 屬于Vue的全局 api,在實(shí)際業(yè)務(wù)開發(fā)中我們很少使用,因?yàn)橄啾瘸S玫?nbsp;Vue.component寫法使用 extend 步驟要更加繁瑣一些,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下2022-09-09Vue.js中provide/inject實(shí)現(xiàn)響應(yīng)式數(shù)據(jù)更新的方法示例
這篇文章主要介紹了Vue.js中provide/inject實(shí)現(xiàn)響應(yīng)式數(shù)據(jù)更新,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10Vue3+TS項(xiàng)目中eslint、prettier安裝配置詳細(xì)指南
為了更好的統(tǒng)一項(xiàng)目的代碼風(fēng)格,因此在編寫時(shí)就可以使用eslint+prettier,它們不僅能方便代碼編寫,還能避免不必要的錯誤,讓代碼變得更加嚴(yán)謹(jǐn),這篇文章主要給大家介紹了關(guān)于Vue3+TS項(xiàng)目中eslint、prettier安裝配置的相關(guān)資料,需要的朋友可以參考下2024-07-07