diff --git a/packages/sticky/index.ts b/packages/sticky/index.ts index b433e281f..0b0906352 100644 --- a/packages/sticky/index.ts +++ b/packages/sticky/index.ts @@ -49,6 +49,7 @@ VantComponent({ mounted() { this.onScroll(); + this.observeWrap(); }, methods: { @@ -130,5 +131,16 @@ VantComponent({ (resolve) => nodesRef.boundingClientRect(resolve).exec() ); }, + + observeWrap() { + // 如果子元素没有内容了 高度为0 取消掉fixed + const observer = wx.createIntersectionObserver(this); + observer.relativeToViewport(); + observer.observe(`.van-sticky-wrap`, (res) => { + if (!res.boundingClientRect.height) { + this.setDataAfterDiff({ fixed: false, height: 0 }); + } + }); + }, }, });