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

326
Views
¿Por qué no puedo representar el valor AJAX JSON?

Aquí está mi código:

 <ul> <li v-for="value in RandomTopic" :key="value.id">{{ value.title }}</li> </ul> export default { data() { return { RandomTopic: null } }, mounted() { ///some method to get data from remote server console.log(res.data); this.RandomTopic = res.data; } }

Quiero renderizar todos los datos del servidor remoto en el front-end. Sin embargo, después de ejecutar el programa, informa este error:

 Cannot set property 'RandomTopic' of undefined ; at api request success callback function TypeError: Cannot set property 'RandomTopic' of undefined

El console.log(res.data); registre el JSON con éxito, por lo que parece que no es un problema de AJAX o del servidor remoto.

Y también, aquí hay una muestra del JSON:

 [ { "id": 421, "title": "sample1", "image_url": "bus.png" }, { "id": 535, "title": "sample78", "image_url": "car.png" } ]

¿Qué pasa con mi código? Soy un principiante de Vue 3, por favor ayúdenme.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Según el error que mencionó, el problema está básicamente relacionado con el alcance de this archivo . Parece que está utilizando una función regular en lugar de una función de flecha ( => {...}) que no proporciona su propio enlace (retiene este valor del contexto léxico adjunto).

Referencia - Función de flecha

 .then(res => { this.RandomTopic = res.data; })
about 4 years ago · Santiago Gelvez 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!