分页功能:
1. 判断当前页和总页数 2. 追加数据
This commit is contained in:
		
							parent
							
								
									768ecbcabc
								
							
						
					
					
						commit
						e24fdd64d3
					
				@ -42,6 +42,20 @@
 | 
				
			|||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script> 
 | 
					<script> 
 | 
				
			||||||
 | 
					// 请求参数, 放全局变量
 | 
				
			||||||
 | 
					const Params = {
 | 
				
			||||||
 | 
					  // 关键字
 | 
				
			||||||
 | 
					  query: "",
 | 
				
			||||||
 | 
					  // 分类id
 | 
				
			||||||
 | 
					  cid: null, 
 | 
				
			||||||
 | 
					  // 页码
 | 
				
			||||||
 | 
					  pagenum: 1,
 | 
				
			||||||
 | 
					  // 页容量 一页有几条数据
 | 
				
			||||||
 | 
					  pagesize: 10
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					// 总页数
 | 
				
			||||||
 | 
					let TotalPage = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
  data(){
 | 
					  data(){
 | 
				
			||||||
    return{
 | 
					    return{
 | 
				
			||||||
@ -63,28 +77,33 @@ export default {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async onLoad ({ id }){
 | 
					  async onLoad ({ id }){
 | 
				
			||||||
    console.log(id)
 | 
					    Params.cid = id
 | 
				
			||||||
    const params = {
 | 
					    this.getGoods()
 | 
				
			||||||
      // 关键字
 | 
					  },
 | 
				
			||||||
      query: "",
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // 分类id
 | 
					  // 滚动条到底触发
 | 
				
			||||||
      cid: id,
 | 
					  onReachBottom(){
 | 
				
			||||||
 | 
					    // 判断有没有下一页
 | 
				
			||||||
      // 页码
 | 
					    if(Params.pagenum >= TotalPage){
 | 
				
			||||||
      pagenum: 1,
 | 
					      console.log("没有下一页数据了")
 | 
				
			||||||
 | 
					    }else{
 | 
				
			||||||
      // 页容量 一页有几条数据
 | 
					      console.log("翻页")
 | 
				
			||||||
      pagesize: 10
 | 
					      Params.pagenum++
 | 
				
			||||||
 | 
					      this.getGoods()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // 从接口拿数据
 | 
					 | 
				
			||||||
    const {message} = await this.$u.api.getGoods(params)
 | 
					 | 
				
			||||||
    console.log(message)
 | 
					 | 
				
			||||||
    this.goods = message.goods
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
 | 
					    // 从接口拿数据
 | 
				
			||||||
 | 
					    async getGoods (){
 | 
				
			||||||
 | 
					      const {message} = await this.$u.api.getGoods(Params)
 | 
				
			||||||
 | 
					      console.log(message)
 | 
				
			||||||
 | 
					      // 追加数据
 | 
				
			||||||
 | 
					      this.goods = [...this.goods, ...message.goods]
 | 
				
			||||||
 | 
					      // 总页数
 | 
				
			||||||
 | 
					      TotalPage = Math.ceil(message.total / Params.pagesize)
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    // 切换子页面
 | 
				
			||||||
    onTapsChange(index){
 | 
					    onTapsChange(index){
 | 
				
			||||||
      this.tabsCurrent = index
 | 
					      this.tabsCurrent = index
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user