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

305
Views
Vue 3 (composition API) get array length

I'm learning javascript and vue.js 3 composition API. My question is I simply want to get an array length and render at

. The array name : "getForms"

<script>.....
const forms_length = computed(() =>  getForms.value.length)

<template>....
<p> {{form_length}} </p>

I get an error "Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')"

why? and what I should do?

Thank you for your help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should use the computed property this way

<template>
  <p>Array length: {{ formsLength}}</p>
</template>
<script>
  import { computed } from 'vue'
  import {useFormsStore} from '../store/forms'
  setup() {
    const { store } = useFormsStore()
    // if the store.forms array is undefined or not ready,
    // then it returns an empty array
    const getForms = computed(() => { return store.forms || []})
    const formsLength = computed(() => getForms.value.length)

    return {
      formsLength
    }
  }
</script>
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!