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

171
Visualizações
Will $attrs affect vuejs patch?

I use vuejs to render a list and give each item the correct key. Normally, I delete the first item of the array, and all the sub-items in the list will not be updated.

But I found that when adding a v-bind="$attrs" to the sub-items, when I delete any item, all the sub-items will be updated!

Normal code:

new Vue({
        el: "#app",
        components: {
          Item: {
            props: {
              item: Number
            },
            template: `<input :placeholder="item"></input>`,
            beforeUpdate() {
              console.log('Item beforeUpdate')
            },
            updated() {
              console.log('Item updated')
            }
          }
        },
        data() {
          return {
            list: [1, 2, 3]
          };
        },
        template: `
          <div>
            <button @click="list.splice(0, 1)">splice first</button>
            <item v-for="item in list" :key="item" :item="item" />
          </div>
        `
      });

When the above code is running, i click button, will not print anything. Explain that the sub-items component is not updated.

When i modify the component's template as:

<input :placeholder="item" v-bind="$attrs"></input>

and click button, will print 'Item beforeUpdate' and 'Item updated', this is incorrect in my cognition!

Hope someone who knows this can help me, thank you!

about 4 years ago · Juan Pablo Isaza
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