简体   繁体   English

Vue JS - 数据没有被动更新

[英]Vue JS - Data not updating reactively

I have a pagination indicator that shows the number of results on a given page, for example;例如,我有一个分页指示器,它显示给定页面上的结果数; page 1 would show '1-5' and page 2 shows '6-10 out of 50 results' etc.第 1 页将显示“1-5”,第 2 页显示“50 个结果中的 6-10 个”等。

I have set the logic in place and it appears to be working, however for the results to update on any other page except for page 1, I would have to refresh the page every time.我已经设置了逻辑并且它似乎正在工作,但是为了在除第 1 页之外的任何其他页面上更新结果,我必须每次都刷新页面。 Therefore '1-5' always appears.因此“1-5”总是出现。 I'm still learning vue and I'm sure it must be some silly mistake here.我还在学习vue,我敢肯定这里一定是一些愚蠢的错误。 What can I do to have the results update when I change page?更改页面时如何更新结果?

Pagination.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;
  },

Your should replace data:() =>{... to data(){...}您应该将data:() =>{...替换为data(){...}

https://v2.vuejs.org/v2/style-guide/index.html#Component-data-essential 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