vue實現(xiàn)element上傳多張圖片瀏覽刪除功能
更新時間:2023年10月13日 10:22:31 作者:小鄭
這篇文章主要介紹了vue實現(xiàn)element上傳多張圖片瀏覽刪除功能,本文結(jié)合示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
vue原生實現(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">
<!-- 點擊刪除 -->
<i class="el-icon-delete" style="position: absolute;left: 30%;top: 80%;z-index:2;color:#fff;"
@click="handleRemoves(index)"></i>
<!-- 點擊瀏覽 -->
<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>到此這篇關于vue實現(xiàn)element上傳多張圖片瀏覽刪除功能的文章就介紹到這了,更多相關vue element上傳多張圖片內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Vue3使用vue-router如何實現(xiàn)路由跳轉(zhuǎn)與參數(shù)獲取
這篇文章主要介紹了Vue3使用vue-router如何實現(xiàn)路由跳轉(zhuǎn)與參數(shù)獲取,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03
解決vue3項目打包后部署后某些靜態(tài)資源圖片不加載問題
這篇文章主要給大家介紹了如何解決vue3項目打包后部署后某些靜態(tài)資源圖片不加載問題,文中通過圖文結(jié)合的方式講解的非常詳細,有需要的朋友可以參考下2024-05-05
Vue.js中provide/inject實現(xiàn)響應式數(shù)據(jù)更新的方法示例
這篇文章主要介紹了Vue.js中provide/inject實現(xiàn)響應式數(shù)據(jù)更新,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10
Vue3+TS項目中eslint、prettier安裝配置詳細指南
為了更好的統(tǒng)一項目的代碼風格,因此在編寫時就可以使用eslint+prettier,它們不僅能方便代碼編寫,還能避免不必要的錯誤,讓代碼變得更加嚴謹,這篇文章主要給大家介紹了關于Vue3+TS項目中eslint、prettier安裝配置的相關資料,需要的朋友可以參考下2024-07-07

