// wxml文件中
<view class="card-user" style="height:{
{card_height}}px;">
// 内容
</view>
data: {
// 盒子高度
card_height:0
},
// 设置盒子高度
getCard_height(){
var that = this
//创建节点选择器
var query = wx.createSelectorQuery();
//选择class id
query.select('.card-user').boundingClientRect(function (rect) {
let card_height = rect.width*2/3
that.setData({
card_height:card_height
})
}).exec();
},
onShow() {
this.getCard_height()
},