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

132
Visualizações
check props value in child component if available

I'm working currently with BootstrapVue.

I have a b-dropdown in my parent.vue where I can select a object of a JSON-File and convert it into an array because I need the length of this json object. This works fine!!

My problem is that I need to check in my parent.vue if something was selected - so if this.arrayLength is higher than 0 (until this point it works all well!). If this is true, it should use and show addElementsNotClickable() in my child.vue where no elements can be added (count of the inputs are equal to length of array) - otherwise it should use and show my button addElement() where multiple elements can be added manually.

But I'm not able to check in my child.vue if arrayLenght > 0... AND i don't know what to use on second button e.g @change(??) How can I solve that?

Many thanks! I've tried to be as detailed as I can!

Additional Info: I get no error codes!!

my parent.vue:

methods: {
  inputedValue(input, index) {
    var array = [];
    const item= this.json.find((i) => i.Number === input);
    for (let key in item.ID) {
      array.push(item.ID[key]);
    }
    if(array.length > 0) {
      this.getIndex = index;
      this.getDataArray = array;
      this.getLengthArray = array.length;
    }
  }
}

my child.vue (template)

<div class="mt-4 mb-5 ml-3 mr-3">
  <b-button v-if="!hide" @click="addElement" variant="block">Add Element</b-button>
  <b-button v-if="hide" @???="addElementNotClickable" variant="block">Not clickable ! </b-button>
</div>

my child.vue (script)

methods: {
  addElementsNotClickable() {
      for(let i = 1; i < this.arrayLength; i++) {
        this.inputs.push({})
      }
  },

  addElement() {
      this.inputs.push({})   
  },
}

data() {
  return {
    inputs: [{}]
    arrayLength: this.getLengthArray,
    arrayIndex: this.getIndex,
    hide: false,
}

props: [
    "getLengthArray",
    "getIndex"
    ],
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are misunderstanding how components should work in Vue. In short you can understand them by:

parent send props down and child send events up

vue component events

What you are looking for is that whenever your arrayLength updates, you send an event to the parent. Then, it is the responsibility of the parent to handle that event. In this case, the parent would receive the event and store the length of the array.

Parent.vue

<template>
  <div> 
    <child @arrayLenght:update="onArrayLenghtUpdate"/>
  </div>
</template>

<script>
export default {
  data: () => {
    arrayLength: 0,
  },
  methods: {
    onArrayLenghtUpdate(length) {
      this.arrayLength = length;
    }
  }
}
</script>

Child.vue

<template>  ... </template>
<script>
export default {
  data: () => ({
    arrayLength: 0,
  }),
  watch: {
    arrayLenghth: function (newLenght) {
       this.$emit('arrayLenght:update', newLenght);
    }
  }
}
</script>

This is the standard way and extremely useful if your Parent and Child aren't highly coupled together. If they are dependent on each other (you won't use Child.vue anywhere else in the app. Just as direct child of Parent.vue) then you can use the inject/provide approach. This approach is beyond the scope of this answer, feel free to read an article on it

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