Vue實現(xiàn)多圖添加顯示和刪除
更新時間:2021年05月27日 15:44:18 作者:吃魚吐泡泡
這篇文章主要為大家詳細(xì)介紹了Vue實現(xiàn)多圖添加顯示和刪除,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了Vue實現(xiàn)多圖添加顯示和刪除的具體代碼,供大家參考,具體內(nèi)容如下
效果圖:

首先給一個input[type="file"],然后隱藏掉,當(dāng)點擊加號所在的區(qū)域時,觸發(fā)文件選擇的點擊事件。
注意:取src的值時用v-bind:src="imgsrc";用src="imgsrc"或者src="{{imgsrc}}"會報錯。
代碼:(有些樣式省略,主要是添加和刪除方法)
<template>
<div id="originality">
<div class="ipt">主圖:</div>
<div class="picture">
<div class="Mainpicture">
<div class="iconfont icon-jia" @click="uploadPic('filed')"></div>
</div>
<!--主圖可以添加多個圖片-->
<div id="img" v-for="(imgsrc,index) in imgsrcs">
<img id="imgshow" :src="imgsrc">
<div class="iconfont icon-cha" @click="deleteMulPic(index)"</div>
</div>
</div>
<input id="filed" type="file" multiple="multiple" accept="image/*,application/pdf" style="display: none;" @change="changeMulPic()">
</div>
</template>
<script>
export default {
name: "originality",
components: {
},
data() {
return {
imgsrcs: []
}
},
methods: {
uploadPic: function(val) {
document.getElementById(val).click();
},
changeMulPic: function() {
var file = $("#filed").get(0).files[0];
$("#img").show();
this.imgsrcs.push(window.URL.createObjectURL(file))
},
deleteMulPic: function(index) {
this.imgsrcs.splice(index, 1);
}
}
}
</script>
<style scoped>
.Mainpicture {
float: left;
width: 100px;
height: 100px;
background: rgba(255, 255, 255, 1);
border-radius: 2px;
border: 1px solid #E5E9F2;
}
.picture {
min-height: 100px;
}
.files {
display: none;
float: left;
}
#img {
margin-left: 20px;
float: left;
width: 100px;
height: 100px;
border-radius: 2px;
border: 1px solid #E5E9F2;
}
.icon-cha {
cursor: pointer;
position: absolute;
width: 10px;
height: 10px;
margin-left: 85px;
margin-top: -100px;
color: #BFC5D1;
}
#imgshow {
width: 100px;
height: 100px;
}
.icon-jia {
text-align: center;
width: 20px;
height: 20px;
line-height: 20px;
color: #BFC5D1;
padding: 40px;
cursor: pointer;
}
</style>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3+Vite+TS實現(xiàn)二次封裝element-plus業(yè)務(wù)組件sfasga
這篇文章主要介紹了在Vue3+Vite+TS的基礎(chǔ)上實現(xiàn)二次封裝element-plus業(yè)務(wù)組件sfasga,下面文章也將圍繞實現(xiàn)二次封裝element-plus業(yè)務(wù)組件sfasga的相關(guān)介紹展開相關(guān)內(nèi)容,具有一定的參考價值,需要的小伙伴可惡意參考一下2021-12-12
vue3 微信掃碼登錄及獲取個人信息實現(xiàn)的三種方法
本文主要介紹了vue3 微信掃碼登錄及獲取個人信息實現(xiàn)的三種方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03

