Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
Vue 3: Flattening a reactive array of objects without destroying reactivity

When I try to flatten a Vue 3 reactive array of nested objects, I lose their reactivity and my app literally crashes and hangs the browser window.

My Vue 3 component defines an array as a list of objects:

this.grouped = [
          [this.tokens[0]],
          [this.tokens[1]],
          [this.tokens[2],this.tokens[3],this.tokens[4]], // nested
          [this.tokens[5]]
]

I need to take the the 2nd index (where the array nests 3 objects) and flatten it so that the resulting array looks like it would have been defined like this:

this.grouped = [
          [this.tokens[0]],
          [this.tokens[1]],
          [this.tokens[2]], //flattened
          [this.tokens[3]], //flattened
          [this.tokens[4]], //flattened
          [this.tokens[5]]
]

When I try to use splice to do this, the reactivity is lost (example below, showing the lost reactivity. Any ideas how to do it?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try Array#flat:

const res = this.grouped.flat();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda