Hi_Jacky123 2022-09-17 20:44 采纳率: 77.8%
浏览 37

微信小程序获取自定义tabbar的高度总是为0,怎么回事?

我使用custom-tab-bar自定义了一个tabbar,里面的内容使用的vant weapp样式,显示和切换正常。

<view id="van-tabbar-id">
    <van-tabbar active="{{active}}" bind:change="onChange">
        <van-tabbar-item wx:for="{{list}}" wx:key="index">
            <image
        slot="icon"
        src="{{item.iconPath}}"
        mode="aspectFit"
        style="width: 25px; height: 25px;"
      />
      <image
        slot="icon-active"
        src="{{item.selectedIconPath}}"
        mode="aspectFit"
        style="width: 25px; height: 25px;"
      />
    {{item.text}}
        </van-tabbar-item>
    </van-tabbar>
</view>

在view中定义了一个id="van-tabbar-id"。方便获取组件尺寸。
我把鼠标放在上图红圈中,左侧显示该view尺寸为320*0,也就是tabbar的宽度为320,高度为0。
我分别在ready()中打印rect,在attached()中打印rect,均显示rect.width = 320,rect.height = 0。同时,rect.top=0,rect.bottom=0.

img

ready: function() {
    // 获取tabber栏的高度
    const query = wx.createSelectorQuery().in(this);
    query.select('#van-tabbar-id').boundingClientRect((rect) => {
      console.log(rect)
    }).exec()
  },

attached() {
    var obj = this.createSelectorQuery();
    obj.select('#van-tabbar-id').boundingClientRect(function (rect) {
      console.log('获取tabBar元素的高度',rect.height);
    }).exec();
  },

请朋友帮忙看看,问题出在哪里?
  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-17 21:22
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 9月17日

悬赏问题

  • ¥15 cesium二维地图绘制实体rectangle颜色问题
  • ¥15 网络分析仪面板参数解释
  • ¥15 车载image sensor的 datasheet
  • ¥15 kotlin multiplaform 的共享模块支持蓝牙吗还是说安卓和ios的蓝牙都要自己配
  • ¥15 为什么我的查询总是显示无数据,该怎么修改呢(语言-java)
  • ¥15 IDDPM采样结果异常
  • ¥100 求一个,王者荣耀查询隐藏战绩的教材,爬虫代码
  • ¥60 Cocos creator缓动问题
  • ¥15 专业问题提问,7月5号2点之前
  • ¥25 使用cube ai 导入onnx模型时报错