Easy task tracker in Vue.js

I’m currently delving into the world of VueJS and working on a simple to-do list application. The issue I’m facing is that I can't seem to successfully pass an array to the child component responsible for displaying the list:

Parent Component

<template>
  <div class="container">

    <div class="row">
      <div class="col-xl-5 mx-auto">
        <form @submit.prevent="submitForm()">
          <div class="row form-group mb-2">
            <div class="col-xl-12">
              <input type="text" placeholder="Name" v-model="stati.nome" class="form-control" @input="v$.nome.$touch" :class="{ 'is-invalid': v$.nome.$error, 'is-valid': !v$.nome.$invalid}"/>
            </div>
          </div>
          <div class="row form-group mb-2">
            <div class="col-xl-12">
              <input type="text" placeholder="Surname" v-model="stati.cognome" class="form-control" @input="v$.cognome.$touch" :class="{ 'is-invalid': v$.cognome.$error, 'is-valid': !v$.cognome.$invalid}"/>
            </div>
          </div>
          <div class="row form-group mb-2">
            <div class="col-xl-12">
              <button type="submit" class="btn btn-success">Submit</button>
            </div>
          </div>
        </form>
        <TabellaCandidati :Candidati="Candidati"></TabellaCandidati>
      </div>
    </div>
  </div>

</template>

<script setup>
import { ref, reactive, computed } from 'vue'
import { useVuelidate } from '@vuelidate/core'
import { required } from '@vuelidate/validators'
import TabellaCandidati from './TabellaCandidati.vue';

    const stati = reactive({
        nome: '',
        cognome:'',
    })
    const regole = computed(() => {
      return{
        nome: { required },
        cognome: { required },
      }
    })
    
    const v$ = useVuelidate(regole, stati)


    const Candidati = ref([]);
    
    const submitForm = async () =>{
      const FormValidato = await v$.value.$validate();
  
      if (FormValidato) {
        Candidati.value.push({
          id:  Math.floor(Math.random() * 100),
          nome: stati.nome,
          cognome: stati.cognome,
        })
      }

    }


</script>

Child Component

<template>
    <table class="table">
        <thead>
            <tr>
            <th scope="col">#</th>
            <th scope="col">Name</th>
            <th scope="col">Surname</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th scope="row">1</th>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </tbody>
    </table>
    
</template>

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

    const {Candidati} = defineProps(['Candidati']);
    
</script>

Where am I going wrong? Apologies, still in the learning phase...

I’m attempting to send an array containing the child component list, but I keep encountering the error "Destructuring the props will cause the value to lose reactivity."

Answer №1

The reason for not destructing the ref variable passed into the child component here is that it would result in losing reactivity, as mentioned in the error message. For more details, refer to this discussion on props destructuring in vue 3.3 alpha 4

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

Chaining promises: The benefits of attaching an error handler during Promise creation versus appending it to a variable containing a promise

function generatePromise() { return new Promise((resolve, reject) => { setTimeout(reject, 2000, new Error('fail')); }); } const promise1 = generatePromise(); promise1.catch(() => { // Do nothing }); promise1 .then( ...

The matMul function encountered an error due to a mismatch in the inner shapes of the Tensors. The shapes provided were 684,1 and 2,1, and the transposeA and transposeB parameters were both set

I am completely new to the world of AI and tensorflow.js. Currently, I am following a Machine Learning course by Stephen Grider. I was expecting an output after running the code below, but instead, I encountered an error. Can someone please assist me? Her ...

Items seem to vanish into thin air and become immovable when attempting to relocate them

I am attempting to create a unique grid layout with 3x3 dimensions, where each grid item represents a fragment of a single image. These items should have the capability to be dragged and dropped inside another 3x3 grid, in any desired sequence. I have hit ...

Challenges faced with password hashing in Express.js

Can anyone assist me with the process of hashing passwords? I had a functional login/register feature on my express app until I integrated bcrypt. After registering a User, I can see that the password is hashed in the Database. However, when attempting to ...

Executing an http.get request in Angular2 without using RxJS

Is there a method to retrieve data in Angular 2 without using Observable and Response dependencies within the service? I believe it's unnecessary for just one straightforward request. ...

Utilizing ASCII art in React: A guide to incorporating textual designs into your

I'm having trouble displaying ASCII images correctly on my React app. I've tried various methods, but nothing seems to maintain the form when rendered in the browser. <Grid container id="terminal_banner"> <Grid item ...

Incorporating JavaScript and Alpine.js to Monitor and Log Changes in Input Range Values

I have developed a basic app that logs the input range value to the console when the range input changes. Interestingly, it works flawlessly when I slide the slider left and right with my cursor. However, when I programmatically change the value using Ja ...

AngularJS $HTTP service is a built-in service that makes

I am facing an issue with pulling the list of current streams from the API and iterating that information with AngularJS. I have tried inputting the JSON data directly into the js file, and it works fine with Angular. However, when I use an http request as ...

I want to integrate a Google translate plugin into my Vue App, but I'm unsure where to

Is there a way to integrate the Google Translate plugin into my Vue App? I have the following code snippet: <div id="google_translate_element"></div><script type="text/javascript"> function googleTranslateElementInit() { new google.tra ...

Exploring the process of setting up Jasmine tests for both services and controllers in Angular.js

I have been facing challenges in creating accurate tests for my Angular services and controllers, even though they are functioning correctly. I have searched extensively for a solution to this problem. Below is an example of my controller: angular.module ...

Styling components using classes in Material-UI

I recently started using material-ui and noticed that it applies inline styles to each component. After running a test with multiple instances of the same component, I realized that there was no CSS-based styling - only repeated inline styles were generate ...

Proper syntax for writing this line in Vue is as follows:

Can you identify the correct syntax for this Vue line: <iframe src="/'product.id'/file.php' " frameborder="0"></iframe> It has been transformed into: <iframe src="/5/file.php"> ...

JavaScript - Modify the proposed content prior to inserting it into the input field

In my current project, I have implemented a feature using jQuery UI - v1.11.4, where an HTML textbox utilizes a JavaScript autocomplete functionality. The suggested string for the textbox is created by concatenating several columns (patient_no, patient_nam ...

A Vue component that dynamically switches between using the router-link or href property

I'm in the process of creating a dynamic menu using the code below: <v-list-item v-for="item in items" :key="item.title" link :to="item.to"> <v-list-item-action> <v-icon>{{item.icon}}</v-icon> </v-list-item- ...

What is the best way to merge two tables together using the server-side JQuery Datatable plugin?

I recently came across an amazing example of a server-side ColdFusion jQuery datatable on this website: Check it out here However, I am facing an issue with adding a second table in the lookup. Specifically, while the primary table lists location_id, I al ...

After my jQuery functions are executed, my CSS rules are loaded

Struggling with the communication between CSS and jQuery, I find myself torn. In CSS, my rules are often very specific, like this: div#container > div#contentLeft { //Code here } However, when I add jQuery to spice up my site, the CSS rules seem to ...

Divide the sentence using unique symbols to break it into individual words, while also maintaining

Is there a way to split a sentence with special characters into words while keeping the spaces? For example: "la sílaba tónica es la penúltima".split(...regex...) to: ["la ", "sílaba ", "tónica ", "es ", "la ", "penúltima"] ↑ ...

Transform a flat 2D shape into a dynamic 3D projection using d3.js, then customize the height based on the specific value from ANG

Currently, I am utilizing d3.js version 6 to generate a 3D representation of the 2D chart shown below. Within this circle are numerous squares, each colored based on its assigned value. The intensity of the color increases with higher values. My goal is t ...

Exploring Vuetify: Navigating Through Sub-Menus on a Drawer

My goal is to create a navigation drawer with expandable sub-menus for specific options. For example, the main menu option "User Profile" may have sub-menus like "Update Contact Details" and "Review Registration". I've experimented with different app ...

Stopping a velocity.js animation once it has completed: is it possible?

For the pulsating effect I'm creating using velocity.js as a fallback for IE9, refer to box2 for CSS animation. If the mouse leaves the box before the animation is complete (wait until pulse expands and then move out), the pulsating element remains vi ...