B
B
Bogdan2018-02-09 15:24:58
Vue.js
Bogdan, 2018-02-09 15:24:58

Is the computed property an array?

Hello. There is such a component

export default {
  props: {
    db: {
      type: Array,
      default: ( ) =>  [ ]
    }
  },
  data() {
    return {
      peoples: this.db,
      listCount: 5,
      activePage: 0
    }
  },
  computed: {
    count: function( ) { return this.db.length+10 },
    pagesCount: function( ) { return Math.ceil( this.count / this.listCount ) },
    pages: function( ) {
      const pageCount = this.pageCount;
      console.log(this.pageCount); // undefined
      return new Array( pageCount ) },
  }
}

The computed property pages is always one element. During the initialization of this property, I understand that at the beginning of the pages initialization, the pagesCount variable is still initialized, but then the array for some reason is not reactive and was not recalculated when the pagesCount value was set.
console.log(this.pageCount); // undefined
5a7d92fead632934689144.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Zharov, 2018-02-09
@bogdan_uman

It seems like a bug... pageCount and pagesCount are they intended, or are they not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question