微信小程序获取自定义元素的宽高、使用”事件穿透”来达到状态同步的效果
微信小程序获取元素宽高的方式: // 自定义组件需要用:this.createSelectorQuery() const query = wx.createSelectorQuery() query.select('.my-class').boundingClientRect(res => { this.setData({ itemHeight: res.height, itemWidth: res.width }) }).exec() 这里需要注意一下: 如果是自定义组件或包含自定义组件的页面中,应该使用this.createSelectorQuery()替代!
下载地址
用户评论