Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

378
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!