vue + element realized paging list data (background data connection)

1, is written below the table

<el-pagination ref="pager1"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
data () {
      return {
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
      }
    },

3.methods in:

XXXXXXData () {
        this.$http({
          url: this.$http.adornUrl('/后台数据连接'),
          method: 'get',
          params: this.$http.adornParams({
            'name': this.listQuery.name,       //这里是我项目的搜索框
            'page': this.pageIndex,          //当前页
            'limit': this.pageSize              //每页显示范围
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.tableData = data.page.list     // 把传回来数据赋给tableData(列表中的数据)
            this.totalPage = data.page.totalCount    //数据总条数
          } else {
            this.tableData = []
            this.totalPage = 0
          }
          console.log(JSON.stringify(data))
        }).catch(function (error) {     //这句话可以忽略,如有错误在控制台显示错误
          console.log(error)
        })
      },

4. On the following two methods to write, or click on the page data are not changing the feed. Note XXXXXXData I called (), to call if you are already a good background data, modify the third step, the fourth step XXXXXXData here () method that you have changed the background connect just fine

     // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.XXXXXXData()     
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.XXXXXXXData()
      },

5. Everyone background may return json format is not the same, I was in this format, appropriate changes according to their own backstage pass over format

{
"msg":"success",
"code":0,
"page":    	
	{
	"totalCount":数据条数,
	"pageSize":每页显示条数,
	"totalPage":分页数,
	"currPage":当前所在页数,
	"list":[{
	     表格数据...
	     }]
	 }
}
Published 38 original articles · won praise 1 · views 5167

Guess you like

Origin blog.csdn.net/ShangMY97/article/details/103250275