簡體   English   中英

Vue JS - 數據沒有被動更新

[英]Vue JS - Data not updating reactively

例如,我有一個分頁指示器,它顯示給定頁面上的結果數; 第 1 頁將顯示“1-5”,第 2 頁顯示“50 個結果中的 6-10 個”等。

我已經設置了邏輯並且它似乎正在工作,但是為了在除第 1 頁之外的任何其他頁面上更新結果,我必須每次都刷新頁面。 因此“1-5”總是出現。 我還在學習vue,我敢肯定這里一定是一些愚蠢的錯誤。 更改頁面時如何更新結果?

分頁.vue

<!-- Results counter -->
    <PaginationResultIndicator :total-items="paginationData.totalItems"
                               :first-item="firstItem"
                               :last-item="lastItem"/>


// Script
data: () => ({
    currentPage: -1,
    limit: undefined,
    firstItem: undefined,
    lastItem: undefined
  }),

created() {
    this.currentPage = this.paginationData.current; 
    this.limit = this.paginationData.totalItems / this.paginationData.totalPages
    this.lastItem = this.limit * this.paginationData.current;
    this.firstItem = this.lastItem - this.limit + 1;
  },

您應該將data:() =>{...替換為data(){...}

https://v2.vuejs.org/v2/style-guide/index.html#Component-data-essential

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM