Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
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
      },
    }
  },
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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>

about 4 years ago · Juan Pablo Isaza Report

0

You declare a function which calculates expired, but you don't call and execute it. Try this:

  expired: (() => {
    var a = []
    for (var i = 1; i < 31; i++) { 
      a.push(i)
    }
    return a
  })(),

But for this particular example there is a more clear solution:

expired: new Array(30).fill().map((d, i) => i + 1)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!