[Vuejs]-Size of the Set in vueJs

2๐Ÿ‘

I think the best way to handle this is to use a computed property.

var app = new Vue({ 
    el: '#app',
    data: {
        message: 'Hello Vue!',
        weeks: new Set()
    },
    computed: {
        weeksSize(){
            return this.weeks.size
        }
    }
});

Then you can use your "weeksSize" also in your methods with "this.weeksSize".

Check the documentation for computed property for more informations.

๐Ÿ‘คMarcelCode

1๐Ÿ‘

You need a computed property in this case.

{
  data(){return {weeks: new Set()}},
  computed:{numberOfPages:()=>this.weeks.size}
}

https://v3.vuejs.org/guide/computed.html#computed-properties

๐Ÿ‘คDropMania

Leave a comment