'Using arrow function to initialize data() in Vue

Why I cannot get the array of 'expired'? I can see expired is a function, but I want a array.

export default {
  name: 'a',
  data () {
    return {
      labelEnable: "a",
      expired: () => {
        var a = []
        for (var i = 1; i < 31; i++) { 
          a.push(i)
        }
        return a
      },
    }
  },


Solution 1:[1]

You can access that via this.expired() instead of this.expired

new Vue({
  el: '#app',
  data () {
    return {
      labelEnable: "a",
      expired: () => [1, 3],
    }
  },
  mounted() {
    console.log(this.expired())
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <p v-for="elem in expired()">{{ elem }}</p>
</div>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rohìt Jíndal