Tips for utilizing props within a Vue component

I am currently working on a vue Modal component where I have defined a prop containing an array. My intention is to pass this array to another component when the modal is open. However, I am encountering an issue where the prop appears to be undefined when accessed inside my modal component. Even though the prop is recognized in my code, it becomes undefined at a later stage. Can someone please review my code and provide assistance?

script:

<script>
import axios from "axios";

export default {
  name: "AddGroupsModal",

  data : ()=>({
    model : [],
}),
  props:{
    newGroup: []
  },


methods: {

  generateGroup(){
     const newMeeting = {meetingUrl: "", meetingName: "", date: this.selectedDate, 
      startTime: "", endTime: ""};
    let finalMeetingArray = [];

    this.model.forEach((model, i) => {
      const key = `participant${i + 1}`;
      newMeeting[key] = model.voterUniqueName;
      newMeeting.startTime = model.startTime;
      newMeeting.endTime = model.endTime
    })
    finalMeetingArray.push(newMeeting)
    this.newGroup.push(newMeeting)
    console.log(JSON.stringify(this.newGroup)
  }

}
}

</script>

Answer №1

When working with components, it's important to remember that props cannot be modified within the component itself. If you rename your prop from newGroup to model, your JavaScript code should function as intended.

export default {
  name: "AddGroupsModal",

  data : ()=>({
    newGroup : [],
}),
  props:{
    model: []
  },


methods: {

  generateGroup(){
     const newMeeting = {meetingUrl: "", meetingName: "", date: this.selectedDate, 
      startTime: "", endTime: ""};
    let finalMeetingArray = [];

    this.model.forEach((model, i) => {
      const key = `participant${i + 1}`;
      newMeeting[key] = model.voterUniqueName;
      newMeeting.startTime = model.startTime;
      newMeeting.endTime = model.endTime
    })
    finalMeetingArray.push(newMeeting)
    this.newGroup.push(newMeeting)
    console.log(JSON.stringify(this.newGroup)
  }

}
}

Answer №2

Ensure that the prop is being passed in kebab-case instead of camelCase.

If your prop is newGroup, make sure to pass it as follows:

<template>
   <add-groups-modal :new-group="[ ... ]" />
</template>

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

Angular: The function t(...) does not support success - TypeError

My code is generating the error TypeError: t(...).success is not a function. I have tried searching for a solution but haven't been able to figure out why this error is happening in my specific case. Here is a snippet of my JS code. Can anyone point ...

Can JavaScript impact the appearance of the printed version of a website?

Just a quick question - I currently don't have access to a printer. My client is wondering if the hidden elements of the webpage (items that are only visible when clicked on) will be included when printing or if they will remain hidden? ...

The ngx-mat-intl-tel-input plugin is experiencing issues with functionality within the Angular 17 framework

I am currently using Angular 17 and here are the specific Versions/Details: Angular CLI: 17.3.8 Node: 18.20.2 Package Manager: npm 10.5.0 OS: linux x64 Angular: 17.3.12 My goal is to import the ngx-intl-tel-input library in order to validate phone numbers ...

Does Koa.js have a nested router similar to Express?

Are there any libraries available that offer Express-style nested routers? For example: var koa = require('koa'); var app = koa(); var Router = require('???'); var restApiRouter = Router(); restApiRouter.get('/', function*() ...

updateStatusCallback function is not defined in the Facebook example using jQuery

I've been trying to incorporate Facebook integration into my HTML code, specifically adding features like Facebook login and sharing functionalities. However, I've hit a roadblock in the process. Even after searching extensively for solutions, I ...

CORS headers present but AJAX request still fails

A request sent via AJAX from a locally hosted page to a remote server is encountering errors, despite the presence of CORS headers. The JavaScript code for this request is as follows: $.ajax({url: 'http://prox.tum.lt/420663719182/test-upload?Action=S ...

Enabling Javascript compilation while overlooking typescript errors

Currently, I am working in VS Code with create-react-app using TypeScript. Whenever there are type errors, they show up in the browser and prevent compilation by TypeScript. I am looking for a way to only see these errors in the Google console and termin ...

Guide on navigating to a specific page with ngx-bootstrap pagination

Is there a way to navigate to a specific page using ngx-bootstrap pagination by entering the page number into an input field? Check out this code snippet: ***Template:*** <div class="row"> <div class="col-xs-12 col-12"> ...

Is there a way to upload several documents in just one writing?

Can anyone advise me on how to add multiple documents to my Firestore collection using just one write operation? I have over 20,000 records and I'm looking for a cost-effective solution. Is there a way to add multiple docs in a single write? Apprecia ...

Develop an innovative showcase page showcasing 151 individual profiles with React Router

I am new to using React Router and feeling a bit confused about how to proceed. On my homepage, I have 151 unique monster thumbnails. When a user clicks on a thumbnail, they should be directed to the specific monster's 'show page'. Currently ...

Avoiding redundant EventEmitters when transferring @Output to a child component

While working on a form component, I decided to separate the form action buttons into a child component. This led me to create two EventEmitter and handlers for the same action. I'm wondering if there is a way to directly pass the 'onDiscard&apo ...

Submit data in the manner of a curl request

Instead of using a curl command to push a file to a web server, I am attempting to create a simple webpage where I can select the file and submit it. Here is the HTML and JavaScript code I have written for this purpose: <html> <body> <i ...

Errors in Ionic 6 involving the FormBuilder, FormGroup, Validators, FormControl, and ControlContainer

I am currently working on creating a basic registration form using Ionic 6.12.3 ionic -V, Angular CLI version 11.0.5, and npm version 6.14.11. You can find the repository for this project here: Repo. Below is my implementation for the register.page.ts: // ...

How can I show a view page in a specific div element using CodeIgniter?

Here is how I'm implementing the dashboard view in my controller. My goal is to have a specific page, like the index page, displayed within a div element rather than opening in a new tab. public function index() { $this->load->view('in ...

Is there a way to create an input field that accepts only numbers and behaves like a password field simultaneously?

I am attempting to develop an input field for entering a PIN. I would like the PIN to be masked on mobile devices, similar to how passwords are obscured in password input fields. I came across a suggestion on stackoverflow regarding this, but unfortunately ...

Tips and tricks for sending variables to an iFrame using jQuery functions

My goal is to dynamically change the source, width, and height of an iframe based on the link that is clicked. Currently, I am able to fire the iframe with hardcoded values using the following code: This is what works: $('.myLink').click(functi ...

Step-by-step guide to generating a Paypal Button using Vue 3 script setup

After going through the PayPal Developer Docs, I'm still struggling to understand how to integrate the PayPal Button into Vue.js. The code examples provided are unclear, and I can't determine if it's related to Vue 2, Vue 3, or even Angular. ...

Guide to utilizing the app.locals parameter in JavaScript?

Currently I am in the process of developing a node.js application. In my app.js file, I have loaded a JSON file as app.locals.parameter and now I am attempting to utilize it in my index.hbs. Let's assume: app.locals.componentData = require('./m ...

The Typescript error message states that the type '{ onClick: () => void; }' cannot be assigned to the type 'IntrinsicAttributes'

I'm a beginner in Typescript and I'm encountering difficulties comprehending why my code isn't functioning properly. My goal is to create a carousel image gallery using React and Typescript. However, I'm facing issues when attempting t ...

dynamically passing arguments to an onclick function

I am experiencing an issue with the following HTML element that has an onclick() function dynamically attached. When trying to call the function, it throws an error stating that "ST" is not defined. The variable passed as name is something like "ST-123". C ...