1. <template>
    2. <view class='goods_list'> <!--加入灰色的背景-->
    3. <goods-list :goods="goods"></goods-list>
    4. <view class='isOver' v-if='flag'>---我是有底线的---</view>
    5. </view>
    6. </template>
    7. <script>
    8. import goodsList from '../../components/goods-list/goods_list.vue'
    9. export default {
    10. data() {
    11. return {
    12. pageindex:1,
    13. goods:[],
    14. flag:false
    15. };
    16. },
    17. components:{
    18. 'goods-list':goodsList
    19. },
    20. methods:{
    21. //获取商品列表数据
    22. async getGoodsList(callback){
    23. const res = await this.$myRequest({
    24. url : '/api/getgoods?pageindex='+this.pageindex
    25. })
    26. //this.goods = res.data.message
    27. this.goods = [...this.goods,...res.data.message]
    28. callback && callback() //如果有这个回调函数就调用
    29. }
    30. },
    31. onLoad(){
    32. this.getGoodsList()
    33. },
    34. //下拉刷新
    35. onReachBottom() { //触底就会触发这个函数
    36. console.log('触底反弹')
    37. if(this.goods.length<10*(this.pageindex-1)){
    38. return this.flag = true
    39. }
    40. this.pageindex++ //页码书进行加1
    41. this.getGoodsList()
    42. },
    43. onPullDownRefresh() {
    44. console.log('下拉刷新了')
    45. this.pageindex = 1
    46. this.goods= []
    47. this.flag = false
    48. setTimeout(()=>{
    49. this.getGoodsList(()=>{
    50. uni.stopPullDownRefresh()
    51. })
    52. },1000)
    53. }
    54. }
    55. </script>
    56. <style lang="scss">
    57. .goods_list{
    58. background: #eee;
    59. }
    60. .isOver{
    61. width:100%;
    62. height:50px;
    63. line-height: 50px;
    64. text-align: center;
    65. font-size:28px;
    66. }
    67. </style>

    image.png
    注意里面回调函数的应用!认真看代码