vue循环遍历给div添加id

html部分

 <div class="img-preview" v-for="(img,i) of list" :key="img.imageKey" v-on:mouseenter="changeActive(i+1)" v-on:mouseleave="removeActive(i+1)" :id="i+1"> //这样就给循环出来的div添加了不同的id
        	<div class="mask"></div>
            <i class="el-icon-delete" @click.prevent="delImg(i)" style="display: none;"></i>
            <img class="imgstyle"
                    :src="img.imageUrl || img.thumbUrl"
                    alt=""
                    @click="openNewImg(img.imageUrl || img.url)"
            />
        </div>

js部分

changeActive(index){
        		console.log($('#'+index ));
        		$('#'+index ).find('.el-icon-delete').show();
        	},
        	removeActive(index){
        		$('#'+index ).find('.el-icon-delete').hide();
        	},
posted @ 2018-07-11 14:51  李美玲  阅读(3346)  评论(0编辑  收藏  举报