vue项目中获取v-for标签中的属性值
<div v-for="item in imgList"><img@click="getava($event)" ref="myava" class="mess-ava mess-ava-change" v-bind:src="item.url" /></div>//获取对象getava(event){var target = event...
·
<div v-for="item in imgList">
<img @click="getava($event)" ref="myava" class="mess-ava mess-ava-change" v-bind:src="item.url" />
</div>
imgList:[
{
name: "1",
url: require(`../../public/img/1.jpg`)
},
{
name: "2",
url: require(`../../public/img/2.jpg`)
},
{
name: "3",
url: require(`../../public/img/3.jpg`)
},
{
name: "4",
url: require(`../../public/img/4.jpg`)
},
],
//获取对象
getava(event){
var target = event.target || window.event.srcElement
//获取对应元素的id值
var text = target.getAttribute('src');
console.log("src----------------"+text);
}
更多推荐
已为社区贡献11条内容
所有评论(0)