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

128
Vistas
Two way binding in a custom input field in vue

I am having problems getting access to the text am entering into a custom input field using the v-model vue directive, here are the codes for both the custom input component and the App.vue

This is my custom input field

Input.vue

<template>
    <label >{{label}}</label>
    <input v-model="bindTo" type='type'  required>
</template>

<script>
export default {
    props:['label','type','bindTo']
}
</script>

App.vue

<template>

    <!-- Email -->
        <Input type="email" label="Email" :bindTo="email"/>
        <p>Email : {{email}}</p>


</template>

<script>
import Input from "./Input.vue";

export default {
    components:{
        Input,
    },
data() {
    return {
        email:"",
        password:"",
        role:"developer",
        terms:false,
        tempSkill:"",
        skills:[],
        passwordError:"",
        emailError:"",
    }
},


</script>

I can't have access to the value in the email in my data method. What might be wrong?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In Vue.js, you just simply add v-bind="$attrs" and v-on="$listeners", so you can forward everything from parent to child component.

Input.vue

<template>
    <label >{{label}}</label>
    <input v-bind="$attrs" v-on="$listeners">
</template>

<script>
  export default {
    props: ['label']
  }
</script>

App.vue

<template>

    <!-- Email -->
        <Input type="email" label="Email" v-model="email" required/>
        <p>Email : {{email}}</p>


</template>

<script>
  import Input from "./Input.vue";

  export default {
    components: {
      Input,
    },
    data() {
      return {
        email: "",
        password: "",
        role: "developer",
        terms: false,
        tempSkill: "",
        skills: [],
        passwordError: "",
        emailError: "",
      }
    },
</script>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Going through the docs thoroughly I found the solution that helped solve my problem

Input.vue

<template>
    <label >{{label}}</label>
    <input :value="modelValue" type='type' @input="$emit('update:modelValue',$event.target.value)"  required>
</template>

<script>
export default {
    props:['label','type','modelValue'],
    emits:['update:modelValue']
}
</script>

Then in App.vue

<template>

    <!-- Email -->
        <Input type="email" label="Email" v-model="email"/>
        <p>Email : {{email}}</p>


</template>

<script>
import Input from "./Input.vue";

export default {
    components:{
        Input,
    },
data() {
    return {
        email:"",
        password:"",
        role:"developer",
        terms:false,
        tempSkill:"",
        skills:[],
        passwordError:"",
        emailError:"",
    }
},


</script>

For more details visit the docs as there are other ways to make it work aside this approach https://vuejs.org/guide/components/events.html

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