html代码:
<template>
<view class="home_page">
<view class="body" ref="body">
<view class="ss" ref="ss" @click="goMy">A页面</view>
<view class="eee" @click="goLoginOut">B页面</view>
</view>
<view class="test" :style="styleVar"></view>
</view>
</template>
<script>
export default {
data() {
return {
styleVar: {
}
}
},
methods: {
getStyle() {
let infos = uni.createSelectorQuery().select(".body")
console.log('info', info)
infos.boundingClientRect((data) => {
console.log('data--------->', data)
console.log('data.width', data.width)
console.log('data.height', data.height)
this.styleVar = {
height: data.height + 'px'
}
}).exec()
}
},
mounted() {
this.$nextTick(function(){
this.getStyle()
})
}
}
</script>
<style >
.ss{
width: 100%;
height: 400px;
text-align: center;
background-color: red;
line-height: 400px;
}
</style>
以下是控制台打印出来的数据: