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

168
Views
Vue 3: v-model and emit

I'm trying to use Vue3 two-way biding with v-model, but my emit() doesn't update the parent value. Could you please tell me where I'm wrong? Thank you!

Parent looks like:

<template>
  <div class="card">
    
    <LearnersTable
        v-model:toActivate="toActivate"
      />
      <!-- To control if this is being updated -->
      {{ toActivate.length }}


  </div>
</template>



<script setup>
[...]

// List of person to activate
const toActivate = [];

</script>

And Children (LearnersTable) looks like:

<template>
    [...]

    <tr v-for="row in rows" :key="row.id"  >
        <span>
            <Toggle v-model="row.enabled" @change="onChangeActivate(row)"/>
        </span>
    </tr>
    [...]

</template>

<script setup>
const props = defineProps({
  
  toActivate: {
    type: Array,
    default: () => [],
  },
});

const emit = defineEmits(['update:toActivate']);

const {
  toActivate,
} = toRefs(props);


function onChangeActivate(row) {

  if (row.enabled === true) {
    toActivate.value.push(row);
  }
  emit('update:toActivate', toActivate.value);
}

</script>

I'm omitting a little bit of code here. But the problem is that my emit doesn't work, I don't get the toActivate value updated in the parent.

Thank you !

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try to make it reactive:

<script setup>
import { ref } from 'vue';

// List of person to activate
const toActivate = ref([]);

</script>

and

<LearnersTable
    v-model:to-activate="toActivate"
 />
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!