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

380
Vistas
VUE 3 Component Uncaught ReferenceError on update:modelValue

I catch error "Uncaught ReferenceError: comp1 is not defined" when make emit "update:modelValue" from component.

And it NOT happens in dev, only when I build.

Parent:

<script setup>
import TestComp from "/src/components/TestComp.vue";
</script>
<script>
export default {
  data() {
    return {
      comp1: null // If remove this row - error will stop, but watcher don`t work ofcourse
    };
  },
  components: {
    TestComp
  },
  watch: {
    comp1(n, o) { console.log(o, n) },
  }
};
</script>

<template>
  <TestComp
    v-model="comp1"
    class="form-control"
  />
</template>

Component:

<script>
import { defineComponent } from "vue";

export default defineComponent({
  data() {
    return { input: '' }
  }
});
</script>

<template>
    <input
      type="text"
      v-model="input"
      @change="$emit('update:modelValue', input)"
    />
</template>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You just need to move the TestComp import to the second <script></script>, and remove the first <script setup></script>

And your Parent page should be like this:

<script>
import TestComp from '/src/components/TestComp.vue'

export default {
  data() {
    return {
      comp1: null, // If remove this row - error will stop, but watcher don`t work ofcourse
    }
  },
  components: {
    TestComp,
  },
  watch: {
    comp1(n, o) {
      console.log(o, n)
    },
  },
}
</script>

<template>
  <TestComp v-model="comp1" class="form-control" />
</template>
about 4 years ago · Juan Pablo Isaza Denunciar

0

In child component you should use value attribute and @input event to mimic the v-model directive, and define modelValue as prop:

<script>
import { defineComponent } from "vue";

export default defineComponent({
   props:{
    modelValue:String
  }
});
</script>
<template>
    <input
      type="text"
      :value="modelValue"
      @input="$emit('update:modelValue', input)"
    />
</template>
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