微信小程序如何获取view组件的高度,swiper如何自适应内容高度

微信小程序如何获取view组件的高度,swiper如何自适应内容高度:
获取swiper-item里面的内容view的高度,给swiper的高度赋值既可以自适应内容高度


  
    
		客户名称:
		客户名称:
    
  
		客户名称:
		客户名称:
		客户名称:
		客户名称:
		客户名称:
		客户名称:
    
   
    
    data: {
      height:'',
    heights:[]
    },
onLoad: function(options) {
  setTimeout(function () {//异步
    var query = wx.createSelectorQuery();
    query.selectAll('.list').boundingClientRect()
    query.exec((res) => {
      console.log(res)
      var listHeight = res[0][0].height
      console.log(res[0][0].height)
      this.setData({
        heights: res[0],
        height: listHeight + 'px'
      })
    })
          }, 800)
  },
  changeswiper:function(e){
    console.log(e.detail.current)
  setTimeout(function () {//异步
            var query = wx.createSelectorQuery();//模仿dom获取组件的高度
            query.selectAll('.list').boundingClientRect()
            query.exec((res) => {
              console.log(res)
              var listHeight = res[0][e.detail.current].height
              console.log(res[0][e.detail.current].height)
              that.setData({
                height: listHeight + 20 + 'px'
              })
            })
          }, 800)
  },
```![在这里插入图片描述](https://img-blog.csdnimg.cn/20190912132424186.png)

你可能感兴趣的:(微信小程序如何获取view组件的高度,swiper如何自适应内容高度)