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

Struggling with consolidating values in an array of objects - seeking assistance with Javascript

Currently, I am handling a project where I receive data in the form of an Object Array. My task is to merge values with the same key into one key and convert the values into an array of strings. Below is the sample data I am working with: inputArray = [ ...

steps for signing in to garmin account with javascript

Attempting to set up an Oauth1 login for Garmin using Angular2 and standard http calls, but encountering a pre-flight OPTIONS call error on the initial request to oauth/request_token path. It seems like CORS is not enabled or something similar. Has anyone ...

Is there a specific regular expression that can be used for validating Credit Card Expiry dates in Javascript/Ang

I am currently working on a textfield where users can enter their credit card expiry date in the format mm/yy. To ensure the validity of this input, I have implemented JavaScript validation using regular expressions. Here is an example of what I have tried ...

A method of submitting by simply pressing the enter key alongside clicking on a Bootstrap button

Here is the HTML code I am using to input prompts into a chatbot: <div class="input-group mb-3"> <input type="text" class="form-control" id="chat-input"> <div class="input-group-append ...

Having trouble uploading big files on your Windows system?

My challenge is to successfully upload a large file using Angular. Specifically, I am attempting to upload a Human Genome tar file, which is a minimum of 2.5gb in size. Strangely, when I try to upload the file from Linux using any browser such as Chrome or ...

Cross-Origin Resource Sharing problem: "Preflight request response does not meet access control criteria"

I'm currently tackling a Vue.js/Nuxt.js project that involves sending API requests to 'https://app.arianlist.com'. However, I've encountered some CORS challenges and came across this error message: "Access to XMLHttpRequest at &ap ...

PHP: When an Array Key is Not Defined

https://i.sstatic.net/k2d1Z.png This is the result I am trying to organize and display my data in tables based on the date. I have stored the data from the database in an array for this purpose. However, I am encountering an error warning stating 'un ...

Descending through layers of a flattened array of objects

I've been diving into the world of array of objects and have successfully flattened them. Now I'm faced with the challenge of nesting them based on unique values at different levels. Currently, I'm using the reduce method to achieve this, bu ...

Column Reordering in DataTable Causes Data to be Mapped Incorrectly

I have created a JSBin where you can view the code. However, due to CORS policy restrictions, the ajax URL I used is not functioning properly. The output generated shows that the data is mapped incorrectly in the columns. Can someone please help me figure ...

Retrieving data with JQuery when encountering an XHR error

When I send a jQuery AJAX request and receive a successful response, I am able to retrieve my JSON data. However, if the response code is anything other than 200, I am unable to access the data in the jQuery callback function. This data is crucial as it co ...

Ways to smoothly conclude a loading animation in real-time

I have a unique challenge of creating a loading animation using Adobe After Effects instead of CSS. The main goal is to develop an animation that continuously loops, but when the loading process stops, it ends with a distinct finishing touch. For instance, ...

What is the reason for the addEventListener function not being able to access global variables?

I have set up an event listener function to utilize popcorn.js for displaying subtitles. Additionally, I have created functions that are unrelated to popcorn.js outside of the event listener and declared a global variable array. However, when attempting ...

Developing a new class within a function

In this section of the HTML file, I have set up a form to collect email and password information from new users in order to create a new profile: <form name="userInfo"> <fieldset> <legend>Create a new account</legend> ...

Guidelines on executing a function after page load in meteor

Currently, I am using cursor.observeChanges to monitor new records inserted in MongoDB and trigger a notification when that happens. The issue I am facing is that these notifications are popping up when my app is loaded for the first time or when I navigat ...

Guide on simulating an incoming http request (response) using cypress

Is there a way to mock a response for an HTTP request in Cypress? Let me demonstrate my current code: Cypress.Commands.add("FakeLoginWithMsal", (userId) => { cy.intercept('**/oauth2/v2.0/token', (req) => { ...

Problems with ng-repeat in kenwheeler's AngularJS implementation

Hey there! I'm currently using the slick carousel by ken wheeler, but when I implement ng-repeat on the div, it only shows 'listed images'. I'm not sure what I'm doing wrong here. Any ideas? <section class="regular slider" sty ...

Utilizing Angular to nest a simple component within another component and display it exclusively on a targeted page or parent component

Currently, I am developing a mobile app using Ionic 3 and have created 2 components - Dumb or presentation components. The first component is the <ion-navbar>, which contains another component called <header-wallet-badge></header-wallet-badg ...

Learn the process of utilizing signed URLs in conjunction with ReactJS to securely store files in AWS

I am currently working on a form where I need to attach images along with regular text inputs in order to submit data to my MongoDB. Here is the code for my post creation function: const [postData, setPostData] = useState({ text: '', i ...

Obtaining the source code from a different domain website with the help of jQuery

Is there a way to extract part of the source code from a YouTube page without using server-side programming? I've tried cross-domain AJAX techniques like Yahoo YQL and JsonP. While Yahoo YQL allows me to grab part of the source code, I'm facing ...

HTML: Base64 image not displaying properly due to incorrect height specification

I have a straightforward base64 image that I am having trouble with. The issue is that only the upper half of the image is displaying. If I try to adjust the height using the "style" attribute in the img tag: style="height: 300px;" it shows correctly. Ho ...