瀏覽代碼

修改高度

lex 2 年之前
父節點
當前提交
cd6a101344
共有 1 個文件被更改,包括 5 次插入8 次删除
  1. 5 8
      src/components/o-sticky/index.tsx

+ 5 - 8
src/components/o-sticky/index.tsx

@@ -44,22 +44,20 @@ export default defineComponent({
       this.divStyle.bottom = this.offsetBottom || '0px'
     }
 
-    // nextTick(() => {
-    //   const { height } = useRect((this as any).$refs.div)
-    //   this.sectionStyle.height = `${height}px`
-    // })
     nextTick(() => {
       setTimeout(() => {
         const { height } = useRect((this as any).$refs.div)
+        console.log(height)
         this.sectionStyle.height = `${height}px`
         this.heightV = height
         this.$emit('getHeight', height)
         console.log(height, 'osticky height')
-      }, 200)
+      }, 300)
 
-      // 在次判断高度是否变化
+      // 为了处理头部第一次获取高度不对的问题
       setTimeout(() => {
         const { height } = useRect((this as any).$refs.div)
+        console.log(height)
         if (height !== this.heightV) {
           this.sectionStyle.height = `${height}px`
           this.heightV = height
@@ -81,7 +79,6 @@ export default defineComponent({
     return (
       <div style={[this.sectionStyle]} class={this.mode === 'sticky' && styles.sticky}>
         <div
-          ref="div"
           class={[
             'van-sticky',
             this.mode === 'fixed' ? 'van-sticky--fixed' : '',
@@ -89,7 +86,7 @@ export default defineComponent({
           ]}
           style={[this.divStyle, this.sectionStyle]}
         >
-          {this.$slots.default && this.$slots.default()}
+          <div ref="div">{this.$slots.default && this.$slots.default()}</div>
         </div>
       </div>
     )