欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Vue 循环内部获取图片高度

最编程 2024-07-05 07:08:24
...

在vue循环里面获取图片宽度或者高度,有时候会用到,则可以

 <div class='conmon'  v-for="(item, index) in items">
    <router-link :to="{path: '/art/details',query:{artid:item.app_id,item_id:item.image_id}}">
                      <img :src="item.src" alt="" @load="onImageLoad($event, item,index)"/>
                    </router-link>

</div>

把获取到值增加会原来的数组内

      onImageLoad(event, item,index){
        this.items[index]['width']=event.target.width

        console.log("图片宽度为:" + event.target.width);
      },

这样就可以在之前的循环里面使用了

原文来自: https://www.lllomh.com/article/details?id=11029036

推荐阅读