lex 2 lat temu
rodzic
commit
dc059bb56b
1 zmienionych plików z 13 dodań i 0 usunięć
  1. 13 0
      src/components/o-sticky/index.tsx

+ 13 - 0
src/components/o-sticky/index.tsx

@@ -29,6 +29,7 @@ export default defineComponent({
   data() {
     return {
       divStyle: {} as any,
+      heightV: 0,
       sectionStyle: {
         width: '100%',
         height: 'auto',
@@ -51,9 +52,21 @@ export default defineComponent({
       setTimeout(() => {
         const { height } = useRect((this as any).$refs.div)
         this.sectionStyle.height = `${height}px`
+        this.heightV = height
         this.$emit('getHeight', height)
         console.log(height, 'osticky height')
       }, 200)
+
+      // 在次判断高度是否变化
+      setTimeout(() => {
+        const { height } = useRect((this as any).$refs.div)
+        if (height !== this.heightV) {
+          this.sectionStyle.height = `${height}px`
+          this.heightV = height
+          this.$emit('getHeight', height)
+          console.log(height, 'next osticky height')
+        }
+      }, 1000)
     })
   },
   watch: {