鍍金池/ 問(wèn)答/Java  HTML/ vue的分頁(yè)我一共獲取了total=12條數(shù)據(jù)每頁(yè)設(shè)置顯示10條,為什么點(diǎn)擊第二

vue的分頁(yè)我一共獲取了total=12條數(shù)據(jù)每頁(yè)設(shè)置顯示10條,為什么點(diǎn)擊第二個(gè)頁(yè)碼的時(shí)候是沒(méi)有數(shù)據(jù)的呢?

<template>
<el-main>

<h1>學(xué)校通知</h1>
<ul>
  <li v-for='news in tableData'><router-link :to="'/schoolnotice/'+news.newsID">{{news.title}}</router-link><span>{{news.publishTime}}</span></li>
</ul>
        **分頁(yè)**
<el-pagination
  layout="prev, pager, next"
  :total="total"
  :page-size="10"
  @current-change="handleCurrentChange"
>
</el-pagination>

</el-main>
</template>

<script>
export default {
data() {

return {
  newsList:[],
  total:{},
  tableData: [], //表格顯示數(shù)據(jù)
  allData: [], //總數(shù)據(jù)
}

},

                             **獲取數(shù)據(jù)**

mounted () {

const that = this;
console.log(that);
this.$http.get(
  that.$interface+'getArticlePages?categoryId=2'
)
  .then(function (response) {
    if(response.data.status === 1){
      response.data.data.list.forEach(function(item){
        that.allData.push({
          title:item.title,
          publishTime:item.publishdate,
          newsID:item.articleid,
        });
        that.total = response.data.data.total;
                    **從allData獲取數(shù)據(jù)到tableData** 
        that.tableData = that.allData.slice(0, 10);
        console.log(that.total);
      });
    }else{
      that.$message({
        message: response.data.msg,
        type: 'warning'
      });
    }
  })
  .catch(function (err) {
    console.log(err);
    that.$message({
      message: '數(shù)據(jù) error',
      type: 'warning'
    })
  });

}, 頁(yè)碼點(diǎn)擊事件
methods:{

handleCurrentChange(val) {  //當(dāng)前頁(yè)
  console.log(val);
  this.tableData = this.allData.slice((val - 1) * 10, 10 * val);
}

}
第一頁(yè)數(shù)據(jù)

第二頁(yè)數(shù)據(jù)

獲取的total值

回答
編輯回答
懶洋洋
  1. 找你們后端,如果是做前端分頁(yè)讓他返回所有數(shù)據(jù),也很可能是后端分頁(yè)而你們沒(méi)對(duì)清楚接口

    response.data.data.list.forEach(function(item){
         ...
         console.log(that.total);//打印了10次12 意思是list長(zhǎng)度本來(lái)就是10
    });
  2. 為什么要在list.forEach里面push,如果你只是想格式化數(shù)組用map。更不要在forEach里重復(fù)的執(zhí)行無(wú)用的 that.total = ... that.tableData = ...,10次循環(huán)前面9次都是無(wú)用的賦值。
2018年5月21日 13:51
編輯回答
久不遇

------------ update

撤回之前的回答, 我看錯(cuò)了。汗

會(huì)不會(huì)接口返回的就是 10條數(shù)據(jù)?

2018年7月15日 22:46
編輯回答
離人歸

切換到第二頁(yè)的時(shí)候,檢查下tableData是不是剩下的那兩條數(shù)據(jù)

2018年7月6日 18:14
編輯回答
傲寒

應(yīng)該后臺(tái)接口有問(wèn)題,totallist不匹配

2018年6月30日 20:52
編輯回答
法克魷

看一下你的allData是多少條數(shù)據(jù)

2018年4月25日 17:42