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

200
Views
Es posible tener una DECLARACIÓN IF/ELSE dentro de data() return

Obtengo data de mi API cuando algunos parameters son correctos.

Ahora necesito verificar si tengo algunos datos dentro de current_data o no y quiero cambiar la definición de mi array como puede ver a continuación.

En realidad, lo que probé no funcionó, ¡así que sería un gran placer si alguien pudiera ayudarme!

Mi error: if(current_data != null) me da múltiples errores de que no es una declaración esperada.

 mounted() { get_Data() { var url = "justexample/API" fetch(url) .then((response) => { return response.json(); }) .then((data) => { this.current_data = data; })
 data() { return { current_data: [], //Here I want to check if current data == [] like this: if(current_data != null) { array: [{ id: this.id +=1, name: "", }] } else if(current_data == null { array: [] } } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

En primer lugar, al publicar preguntas: ¿qué no funcionó? ¿Recibiste algún error?

¡No puede poner lógica/ if s en un objeto devuelto por la función de data ! Probablemente tengas que poner tu if en un calculado:

 data() { .... }, computed: { counter() { return this.current_data?.length > 0 ? 1 : 0; // if the current_data array has 0 items return 0, otherwise 1 } }

Luego puede usar el counter calculado en la plantilla: <span>{{ counter }}</span>

about 4 years ago · Juan Pablo Isaza Report

0

Puedes hacer así:

 data() { return { current_data: [], //Here I want to check if current data == [] like this: counter: null; } } mounted() { get_Data() { var url = "justexample/API" fetch(url) .then((response) => { return response.json(); }) .then((data) => { this.current_data = data; if(current_data == []){ this.counter = 0 } } else if(current_data != [] { this.counter = 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!