vue2踩坑之项目:获取和操作动态 DOM 节点

主要是获取动态的dom元素,利用:class属性类名加上index即可,然后js里queryselector获取并且加上index

//html
<div :class="'imageClass'+index" v-for="(item,index) in allDataUrl" 
         :key="index" class="warpBoxs rel">
        ......
</div>

//data
allDataurl:[], //数据数组 


//js
// 下载
async dowloads() {
 .....
  return new Promise(
   resolve) => {
    this.allDataUrl.map((item, index) => {
     let imageWrapper = document.querySelector('.imageClass' + index); //动态获取dom元素
            .........
            })
          }
      ).then((data) => {
        // console.log(data)
     .........
      })
    },

上一篇文章,

uniapp踩坑之项目:TypeError: Cannot read properties of null (reading ‘getAttribute‘)_意初的博客-CSDN博客是因为数据没有取到就切换别的页面,造成dom渲染失效导致,需要利用v-if和页面生命周期进行判断。uniapp踩坑之项目:各端条件编译_意初的博客-CSDN博客。https://blog.csdn.net/weixin_43928112/article/details/130591477

猜你喜欢

转载自blog.csdn.net/weixin_43928112/article/details/130919089