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

115
Views
¿Estoy arruinando la reactividad de Vue.js al recorrer una matriz en el estado y crear nuevas propiedades dentro de cada elemento?

Estoy ejecutando el siguiente código en mi método montado():

 mounted(){ this.sentences = this.sentences.map((sentence, index) => { let words = []; sentence.text.split(' ').forEach((word, i) => { words.push({ text: word, selected: false }) }); sentence.words = words sentence.grade.selected = false; return sentence; }) }

Originalmente, this.sentences se ve así:

 sentences: [ { text: "Go away and hide behind that door where we found you just now.", grade: { text: 606 } }, { text: "Please don't let anyone spoil these nice fresh flowers.", grade: { text: 609 } }, { text: "The string had eight knots in it which I had to untie.", grade: { text: 700 } }, ]

Así que estoy agregando words de propiedad a cada objeto en la matriz de oraciones y una propiedad selected para la propiedad de grado de cada objeto. Después de cambiar de palabras codificadas y propiedades seleccionadas a agregarlas dinámicamente con JavaScript, la reactividad de las palabras dejó de funcionar. Supongo que no los estoy configurando de la manera correcta, pero no puedo entender qué estoy haciendo mal.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Los problemas son las limitaciones al agregar nuevas propiedades a un objeto reactivo.

Use Vue.set para agregar nuevas propiedades.

 Vue.set(sentence, 'words', words) Vue.set(sentence.grade, 'selected', false)

O use una función calculada.

 computed: { sentencesComputed() { return this.sentences.map((sentence, index) => { let words = []; sentence.text.split(' ').forEach((word, i) => { words.push({ text: word, selected: false }) }); sentence.words = words sentence.grade.selected = false; return sentence; }) } }
over 4 years ago · Santiago Trujillo 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!