Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda