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

261
Visualizações
(Vue.js) Importing values from one component to another, not sure if it can be done with props

I'm trying to learn vue and hit a small roadbump - is there a way for me to make this work? I want to push a new value into my items array with my Button component so then i can render it with the v-for. I know it would much be easier to put everything into one file, just curious if it can be done this way. Here is the code:

https://codesandbox.io/s/mystifying-antonelli-7o6m6o?file=/src/App.vue

any help would be much appreciated :)

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

0

Sure this can be done the way you would like. One way to do it is to define the variables and the add function in the App.vue.

<script setup>
import { ref } from "vue";

const name = ref("");
const amount = ref(0);
const items = ref([]);

const addItem = () => {
  items.value.push = { name: name.value, amount: amount.value };
  name.value = "";
  amount.value = 0;
};
</script>

Bind name and amount with your inputs via v-model and bind addItem to your button with @click. You can use items as a prop for your ItemList component.

Your components need changes to work, but I hope this will give you some direction. Perhaps first make it work with plain html input and button elements and use {{ items }} to render the items array. Once that works you can create the custom components.

Hope this helps.

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