Unleashing the Power of Vue 3 with v-model and Emit

Struggling to implement Vue3 two-way binding with v-model, but my emit() isn't updating the parent value. Any idea where I might be going wrong? Much appreciated!

This is what the parent component looks like:

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


  </div>
</template>



<script setup>
[...]

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

</script>

And here's how the children component (LearnersTable) is structured:

<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've left out some code snippets, but the main issue is that my emit doesn't seem to work correctly, resulting in the toActivate value not being updated in the parent.

Appreciate any insights you may have!

Answer №1

Transform it to be responsive:

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

// Array of individuals to activate
const activationList = ref([]);

</script>

also include

<ParticipantsTable
    v-model:activate="activationList"
 />

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Prevent background element from being selected with a double-click

Whenever I double-click on the background, the first element gets selected. How can I prevent this from happening? Here is a fiddle to demonstrate: https://jsfiddle.net/cb6fjr7n/1/ <input style="text" value="lala"/> If you double-click outside of ...

Steps to combine multiple arrays into a unified array:1. Begin by allocating a

To form a league table, I have multiple individual arrays filled with data. In order to sort them by points, I want to merge these arrays into a single array called "teams". However, I am unsure if there is a function available to achieve this specific f ...

Utilizing $index in AngularJS while iterating through ng-repeat items

Here is an example of an unordered list: <ul class="dropdown-menu inner" role="menu"> <li ng-repeat="availableAlphaName in availableAlphaNames" data-original-index="0" data-optgroup="1" class=""> <a tabindex="0" class="opt " st ...

When Vue.js Vuex state changes, the template with v-if does not automatically refresh

I have tried setting the v-if value in computed, data, passing it as props, and directly referencing state, but it never seems to re-render despite the fact that the state I am checking for is changed to true. Currently, I am directly referencing the stor ...

What is the recommended approach for conducting backend validation?

As I develop a CRUD application using express.js and node.js, here is the backend API code that I have written: app.post("/signup", (req, res) => { const { name, email, password } = req.body; if (!name) { res.status(401).json("Please provide a n ...

Activate a click on a div element to enable smooth scrolling when using the page down and page up keys

Whenever I directly click on my div, the pageUp and pageDown keys scroll the contents of the div. But when I trigger a click programmatically, the scrolling with pageUp and pageDown stops working. How can I enable scrolling with pageUp and pageDown without ...

Acquire information from a Card using Oracle Apex

I have a Card Regions that showcases some of my tables. I'd like each card to redirect to a specific page based on a number (the "page_table" number corresponds to the page it will redirect to). Below is the Query for the Cards Region: SELECT table_n ...

Loading all stores simultaneously in ExtJS

In my application.js file, I have defined the code snippet below. It includes a long list of stores and views that need to be loaded. The issue arises because these components are loaded asynchronously. This means that if a user clicks a button before a s ...

Creating dynamic routes in express.js with fixed components

I'm exploring how to create a route in express that captures URLs like this: /events/0.json Here's what I've attempted so far (but it's not working as expected): router.put('/events.json/:id.json', isLogged, events.update) ...

When tab switching occurs, the alert box fails to be processed by the browser

When using the alert(message) function, it will display an alert box with a message and an OK button. It will also pause the execution of any code that follows until the OK button is clicked. However, I have noticed a peculiar situation where switching tab ...

Employing a pair of interdependent v-select components to prevent any duplicate entries

I am currently working with two v-select boxes that share similar data. In my scenario, I extract attachments from an email and load them into an array. The issue I encountered is that the first select box should only allow the selection of one document, w ...

Modifying Label text dynamically using jQuery on Click event

My website HTML contains the following code snippet: <script src="js/jquery.flexslider.js"></script> <script src="js/jquery.rings.js"></script> The contents of jquery.rings.js are as follows: $('input[type="image"]') ...

Deliver asynchronous requests using Web Components (Model-View-Controller)

I am currently working on developing an application using pure javascript and Web Components. My goal is to incorporate the MVC Pattern, but I have encountered a challenge with asynchronous calls from the model. Specifically, I am creating a meal-list com ...

Dealing with errors in Node.js using the Express framework and the

The code I'm having trouble with is shown below app.get('/', function(req, res, next) { if (id==8) { res.send('0e'); } else { next(); } }); app.use(function(err, req, res, next){ res.send(500, ' ...

Tips for integrating AudioControl with Phonegap

I couldn't find a suitable plugin, so I decided to create my own. My goal is to activate silent mode using a JavaScript command, however, I am encountering an error with the undefined method getSystemService. It seems like there may be a problem with ...

Cascading Style Sheets can be disrupted by Scalable Vector Graphics

Currently, I am incorporating SVG Icons that I created in Illustrator into my Vue.js Webapp. I have utilized Webpack's "require" to load the icons. Rather than accessing the SVGs directly using the src attribute of the img tag, I am inserting them usi ...

XCODE encountered an issue while attempting to open the input file located at '/Users/name/Desktop/test/appname/node_modules/react-native-compressor/ios/Video/Compressor-Bridging-Header.h'

Encountering an issue while running my project in XCode. I recently added the react-native-compressor package by following the steps mentioned in the installation guide When attempting to run the project in XCode, the error below occurs: <unknown> ...

Merge two JSON objects together by matching their keys and maintaining the original values

After having two separate JSON objects representing data, I found myself in the position of needing to merge them into one combined result. The initial objects were as follows: passObject = { 'Topic One' : 4, 'Topic Two' : 10, &apos ...

After a texture is added, the shine of the Three.js MeshPhongMaterial diminishes

Check out this intriguing Codepen showcasing a white, glossy "cup" loaded using Three's GLTFLoader: https://codepen.io/snakeo/pen/XWOoGPL However, when I try to add a texture to a section of the mug, the shiny cup mysteriously transforms into a lack ...

Is there a way for me to determine the exact coordinates of all buttons on a given webpage?

I came across this piece of code, but I'm a bit unsure about where exactly I should input it and how to adjust it to locate the position of each button. Additionally, I'm curious as to where the results (coordinates) will be shown? function find ...