一位帅气的前端
一位帅气的前端
  • 发布:2020-07-09 16:43
  • 更新:2020-08-25 16:10
  • 阅读:744

用官方的 waterfall组件里面嵌套header并不能吸顶

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: wind 10

HBuilderX类型: 正式

HBuilderX版本号: 2.7.14

手机系统: Android

手机系统版本号: Android 10

手机厂商: OPPO

手机机型: ace

页面类型: nvue

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

<template>
<view style="width: 100%;height: 100vh;">
<!-- <list style="height: 1000rpx;width: 750rpx;"> -->
<waterfall style="height: 1000rpx;width: 750rpx;" column-count="2" column-width="auto">

            <refresh  class="flex-row align-center justify-center mb-3" style="height: 80rpx;width: 750rpx;" @refresh="refresh" @pullingdown="pullingdown" :display="refreshing">  
              <text>{{text}}</text>  
             </refresh>  

        <cell>  
            <view style="height: 200rpx;">这个地方是一个占位</view>  
        </cell>  
        <header>  
            <view style="height: 200rpx;" class="bg-dark">这个地方是 吸顶</view>  
        </header>  

        <cell v-for="(item,index) in list" :key="index"  :ref="'item'+index"  insert-animation="default" delete-animation="default">  
            <view @click="goDetail" style="width: 50%;" class="bg-primary p-2 mb-2" >  
                <image :src="item.cover" ></image>  
                <text>{{item.name}}</text>  
                <text>{{item.content}}</text>  

            </view>  

        </cell>  
        <loading @loading="onLoading"   
                    :display="loadingShow"><text>dddd</text></loading>  
    </waterfall>  
    <!-- </list> -->  
</view>  

</template>

<script>
export default {
data() {
return {
list:[],
refreshing:'hide',
loadingShow:'hide',
text:'下拉释放刷新...',
loadtext:'上拉加载更多...'
}
},
mounted() {

        for(let i=0;i<60;i++){  
            this.list.push({  
                id:i,  
                name:`瑶----${i}`,  
                content:`又帅又可爱------${i}`,  
                cover:`/static/images/demo/demo${i+1}.jpg`  
            })  
        }  
    },  
    methods: {  
//       topBottom(){  
//          this.$nextTick(()=>{  
//              let index=this.list.length-1;  
//              let ref='item'+index;  
//              if(this.$refs[ref]){  
//                  dom.scrollToElement(this.$refs[ref][0], {})  
//              }    
//          })  
      // },  
      //下拉  
      refresh(){  
          this.refreshing='show'  
          this.text='正在刷新...'  
          setTimeout(()=>{  
              this.refreshing='hide'  
              this.text='下拉释放刷新...'  
          },1000)  
      },  
      pullingdown(e){  
          this.text=e.pullingDistance>e.viewHeight?'释放就可以刷新':'下拉释放刷新...'  
      },  
      goDetail(){  
          uni.navigateTo({  
            url:'../detail/detail'  
          })  
      },  
      onLoading(e){  
        this.loadingShow = 'show';  
        setTimeout(()=>{  
            this.loadingShow = 'hide';  
        },1000)  
      }  
    },  
    onUnload() {  

    }  
}  

</script>

<style>

</style>

操作步骤:

<template>
<view style="width: 100%;height: 100vh;">
<!-- <list style="height: 1000rpx;width: 750rpx;"> -->
<waterfall style="height: 1000rpx;width: 750rpx;" column-count="2" column-width="auto">

            <refresh  class="flex-row align-center justify-center mb-3" style="height: 80rpx;width: 750rpx;" @refresh="refresh" @pullingdown="pullingdown" :display="refreshing">  
              <text>{{text}}</text>  
             </refresh>  

        <cell>  
            <view style="height: 200rpx;">这个地方是一个占位</view>  
        </cell>  
        <header>  
            <view style="height: 200rpx;" class="bg-dark">这个地方是 吸顶</view>  
        </header>  

        <cell v-for="(item,index) in list" :key="index"  :ref="'item'+index"  insert-animation="default" delete-animation="default">  
            <view @click="goDetail" style="width: 50%;" class="bg-primary p-2 mb-2" >  
                <image :src="item.cover" ></image>  
                <text>{{item.name}}</text>  
                <text>{{item.content}}</text>  

            </view>  

        </cell>  
        <loading @loading="onLoading"   
                    :display="loadingShow"><text>dddd</text></loading>  
    </waterfall>  
    <!-- </list> -->  
</view>  

</template>

<script>
export default {
data() {
return {
list:[],
refreshing:'hide',
loadingShow:'hide',
text:'下拉释放刷新...',
loadtext:'上拉加载更多...'
}
},
mounted() {

        for(let i=0;i<60;i++){  
            this.list.push({  
                id:i,  
                name:`瑶----${i}`,  
                content:`又帅又可爱------${i}`,  
                cover:`/static/images/demo/demo${i+1}.jpg`  
            })  
        }  
    },  
    methods: {  
//       topBottom(){  
//          this.$nextTick(()=>{  
//              let index=this.list.length-1;  
//              let ref='item'+index;  
//              if(this.$refs[ref]){  
//                  dom.scrollToElement(this.$refs[ref][0], {})  
//              }    
//          })  
      // },  
      //下拉  
      refresh(){  
          this.refreshing='show'  
          this.text='正在刷新...'  
          setTimeout(()=>{  
              this.refreshing='hide'  
              this.text='下拉释放刷新...'  
          },1000)  
      },  
      pullingdown(e){  
          this.text=e.pullingDistance>e.viewHeight?'释放就可以刷新':'下拉释放刷新...'  
      },  
      goDetail(){  
          uni.navigateTo({  
            url:'../detail/detail'  
          })  
      },  
      onLoading(e){  
        this.loadingShow = 'show';  
        setTimeout(()=>{  
            this.loadingShow = 'hide';  
        },1000)  
      }  
    },  
    onUnload() {  

    }  
}  

</script>

<style>

</style>

预期结果:

<template>
<view style="width: 100%;height: 100vh;">
<!-- <list style="height: 1000rpx;width: 750rpx;"> -->
<waterfall style="height: 1000rpx;width: 750rpx;" column-count="2" column-width="auto">

            <refresh  class="flex-row align-center justify-center mb-3" style="height: 80rpx;width: 750rpx;" @refresh="refresh" @pullingdown="pullingdown" :display="refreshing">  
              <text>{{text}}</text>  
             </refresh>  

        <cell>  
            <view style="height: 200rpx;">这个地方是一个占位</view>  
        </cell>  
        <header>  
            <view style="height: 200rpx;" class="bg-dark">这个地方是 吸顶</view>  
        </header>  

        <cell v-for="(item,index) in list" :key="index"  :ref="'item'+index"  insert-animation="default" delete-animation="default">  
            <view @click="goDetail" style="width: 50%;" class="bg-primary p-2 mb-2" >  
                <image :src="item.cover" ></image>  
                <text>{{item.name}}</text>  
                <text>{{item.content}}</text>  

            </view>  

        </cell>  
        <loading @loading="onLoading"   
                    :display="loadingShow"><text>dddd</text></loading>  
    </waterfall>  
    <!-- </list> -->  
</view>  

</template>

<script>
export default {
data() {
return {
list:[],
refreshing:'hide',
loadingShow:'hide',
text:'下拉释放刷新...',
loadtext:'上拉加载更多...'
}
},
mounted() {

        for(let i=0;i<60;i++){  
            this.list.push({  
                id:i,  
                name:`瑶----${i}`,  
                content:`又帅又可爱------${i}`,  
                cover:`/static/images/demo/demo${i+1}.jpg`  
            })  
        }  
    },  
    methods: {  
//       topBottom(){  
//          this.$nextTick(()=>{  
//              let index=this.list.length-1;  
//              let ref='item'+index;  
//              if(this.$refs[ref]){  
//                  dom.scrollToElement(this.$refs[ref][0], {})  
//              }    
//          })  
      // },  
      //下拉  
      refresh(){  
          this.refreshing='show'  
          this.text='正在刷新...'  
          setTimeout(()=>{  
              this.refreshing='hide'  
              this.text='下拉释放刷新...'  
          },1000)  
      },  
      pullingdown(e){  
          this.text=e.pullingDistance>e.viewHeight?'释放就可以刷新':'下拉释放刷新...'  
      },  
      goDetail(){  
          uni.navigateTo({  
            url:'../detail/detail'  
          })  
      },  
      onLoading(e){  
        this.loadingShow = 'show';  
        setTimeout(()=>{  
            this.loadingShow = 'hide';  
        },1000)  
      }  
    },  
    onUnload() {  

    }  
}  

</script>

<style>

</style>

实际结果:

<template>
<view style="width: 100%;height: 100vh;">
<!-- <list style="height: 1000rpx;width: 750rpx;"> -->
<waterfall style="height: 1000rpx;width: 750rpx;" column-count="2" column-width="auto">

            <refresh  class="flex-row align-center justify-center mb-3" style="height: 80rpx;width: 750rpx;" @refresh="refresh" @pullingdown="pullingdown" :display="refreshing">  
              <text>{{text}}</text>  
             </refresh>  

        <cell>  
            <view style="height: 200rpx;">这个地方是一个占位</view>  
        </cell>  
        <header>  
            <view style="height: 200rpx;" class="bg-dark">这个地方是 吸顶</view>  
        </header>  

        <cell v-for="(item,index) in list" :key="index"  :ref="'item'+index"  insert-animation="default" delete-animation="default">  
            <view @click="goDetail" style="width: 50%;" class="bg-primary p-2 mb-2" >  
                <image :src="item.cover" ></image>  
                <text>{{item.name}}</text>  
                <text>{{item.content}}</text>  

            </view>  

        </cell>  
        <loading @loading="onLoading"   
                    :display="loadingShow"><text>dddd</text></loading>  
    </waterfall>  
    <!-- </list> -->  
</view>  

</template>

<script>
export default {
data() {
return {
list:[],
refreshing:'hide',
loadingShow:'hide',
text:'下拉释放刷新...',
loadtext:'上拉加载更多...'
}
},
mounted() {

        for(let i=0;i<60;i++){  
            this.list.push({  
                id:i,  
                name:`瑶----${i}`,  
                content:`又帅又可爱------${i}`,  
                cover:`/static/images/demo/demo${i+1}.jpg`  
            })  
        }  
    },  
    methods: {  
//       topBottom(){  
//          this.$nextTick(()=>{  
//              let index=this.list.length-1;  
//              let ref='item'+index;  
//              if(this.$refs[ref]){  
//                  dom.scrollToElement(this.$refs[ref][0], {})  
//              }    
//          })  
      // },  
      //下拉  
      refresh(){  
          this.refreshing='show'  
          this.text='正在刷新...'  
          setTimeout(()=>{  
              this.refreshing='hide'  
              this.text='下拉释放刷新...'  
          },1000)  
      },  
      pullingdown(e){  
          this.text=e.pullingDistance>e.viewHeight?'释放就可以刷新':'下拉释放刷新...'  
      },  
      goDetail(){  
          uni.navigateTo({  
            url:'../detail/detail'  
          })  
      },  
      onLoading(e){  
        this.loadingShow = 'show';  
        setTimeout(()=>{  
            this.loadingShow = 'hide';  
        },1000)  
      }  
    },  
    onUnload() {  

    }  
}  

</script>

<style>

</style>

bug描述:

用官方的 waterfall组件里面嵌套header并不能吸顶只有在list包裹下才能吸顶

2020-07-09 16:43 负责人:无 分享
已邀请:
祝三枝

祝三枝

同问

DCloud_uniAD_HDX

DCloud_uniAD_HDX

header 需要设置样式 position: sticky;

  • 3***@qq.com

    怎么实现两个header同时吸顶,一上一下

    2020-11-19 21:59

  • 3***@qq.com

    用监听滚动事件曲线实现了一个,但在一些情况下会闪一下,这并不能让我忍受

    2020-11-19 22:05

  • QLing

    回复 3***@qq.com: 同问

    2022-01-30 10:22

该问题目前已经被锁定, 无法添加新回复