lex 2 vuotta sitten
vanhempi
commit
91785b8089
1 muutettua tiedostoa jossa 7 lisäystä ja 6 poistoa
  1. 7 6
      src/components/o-sticky/index.tsx

+ 7 - 6
src/components/o-sticky/index.tsx

@@ -47,18 +47,18 @@ export default defineComponent({
     nextTick(() => {
       setTimeout(() => {
         const { height } = useRect((this as any).$refs.div)
-        console.log(height)
+        console.log(height, this.position)
         this.sectionStyle.height = `${height}px`
         this.heightV = height
         this.$emit('getHeight', height)
         console.log(height, 'osticky height')
-      }, 300)
+      }, 200)
 
       // 为了处理头部第一次获取高度不对的问题
       setTimeout(() => {
-        const { height } = useRect((this as any).$refs.div)
-        console.log(height)
-        if (height !== this.heightV) {
+        const { height } = useRect((this as any).$refs.div2)
+        console.log(height, this.position, 'next')
+        if (height !== this.heightV && this.position === 'top') {
           this.sectionStyle.height = `${height}px`
           this.heightV = height
           this.$emit('getHeight', height)
@@ -79,6 +79,7 @@ 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' : '',
@@ -86,7 +87,7 @@ export default defineComponent({
           ]}
           style={[this.divStyle, this.sectionStyle]}
         >
-          <div ref="div">{this.$slots.default && this.$slots.default()}</div>
+          <div ref="div2">{this.$slots.default && this.$slots.default()}</div>
         </div>
       </div>
     )