Browse Source

fix(navbar): taro init height error

richard1015 3 years ago
parent
commit
e1be66ab54
1 changed files with 8 additions and 10 deletions
  1. 8 10
      src/packages/__VUE/navbar/index.taro.vue

+ 8 - 10
src/packages/__VUE/navbar/index.taro.vue

@@ -1,6 +1,6 @@
 <template>
   <view v-if="fixed && placeholder" class="nut-navbar--placeholder" :style="{ height: navHeight + 'px' }">
-    <view :class="classes" :style="styles" ref="navBarHtml">
+    <view :class="classes" :style="styles" class="navBarHtml">
       <view class="nut-navbar__left" @click="handleLeft">
         <nut-icon v-if="leftShow" color="#979797" name="left"></nut-icon>
         <view v-if="leftText" class="nut-navbar__text">{{ leftText }}</view>
@@ -91,16 +91,14 @@ export default create({
 
     onMounted(() => {
       if (fixed.value && placeholder.value) {
-        setTimeout(async () => {
+        setTimeout(() => {
           const query = Taro.createSelectorQuery();
-          query
-            .select('.navBarHtml')
-            .boundingClientRect((rec: any) => {
-              navHeight.value = rec.height;
-              console.log('navBarHtml', navHeight);
-            })
-            .exec();
-        }, 100);
+          query.select('.navBarHtml').boundingClientRect();
+          query.exec((res) => {
+            navHeight.value = res[0].height;
+            // console.log('navHeight', navHeight.value)
+          });
+        }, 500);
       }
     });