Child component in Vue 2 not receiving defined props

After numerous attempts, I am still struggling to successfully pass a prop down to a child component.

<Project :grossMarginPerResource="grossMarginPerResource" :threshold="threshold" :orderBy="orderBy" @refetch="refetch" v-if="group_by == 'Project'"></Project>

The child component is supposed to accept this prop:

props: ['grossMarginPerResource', 'orderBy', 'show_costs','threshold'],

Although when trying to access this prop, it always returns as undefined.

If I log the prop in the parent component, here's what is displayed:

{ "green": "1000", "yellow": "400", "red": "400" } 

However, in the child component, running:

console.log(this.threshold)

the output is consistently showing as undefined.

Answer №1

I have successfully implemented the solution by creating a code snippet to pinpoint the root cause. By referencing the code provided, I was able to confirm that the functionality is working as expected. Please review and let me know if there are any particular areas where you are encountering challenges. Utilizing console.log, you can observe the data within the threshold variable across all lifecycle hooks.

Demonstration :

Vue.component('Project', {
  props: ['threshold'],
  template: '<pre>{{ threshold }}</pre>',
  mounted() {
    console.log(this.threshold)
  }
});

var app = new Vue({
    el: '#app',
    data: {
        threshold: { "green": "1000", "yellow": "400", "red": "400" }
    }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <Project :threshold="threshold"></Project>
</div>

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

How to Retrieve Video Length using AJAX in the YouTube API

I have been working on a script to fetch the duration of a YouTube video using its id. Here is the code snippet I've written: var vidID = ""; var vidData; var vidDuration; function getResponse() { $.getJSON( "https://www.googleapis.c ...

Ways to store a filestream coming from Node.js into AngularJS

When using my express server, I have a post-request set up to retrieve a pdf file from Amazon S3 and then send it back to Angular. This is the endpoint in my express server: var fileStream = s3.getObject(options).createReadStream(); fileStream.pipe(res); ...

Can I send both a list of files and an entire JSON object in a FormData object to an ASP.NET CORE MVC Controller?

I'm looking for a way to send a formdata object to an MVC controller that includes both a JSON object with nested objects and a list of files. I've attempted to stringify the object into a JSON object, but the controller is unable to read the pro ...

How can a React app be developed offline?

I am currently working offline with no access to the internet. Node.js is already installed on my system, but I encountered an error when trying to run the command npm create-react-app. Is there a way for me to execute npm commands and set up a react app ...

creating a JSON object

Exploring JSON for the first time and I have a couple of questions: Is it possible to create a JSON object using the 'data-id' attribute and have it contain a single array of numbers? Even though I have the code to do this, I am facing difficul ...

Utilizing AJAX for fetching a partial view

My Web Forms legacy project had a feature where a panel would be displayed when the user clicked on a button. Now, I am working on rebuilding this functionality in C# MVC. The new view will utilize Javascript and AJAX to display a partial view as needed. ...

Change locale in Vue with Vue-i18n

Consider the following code: <ul> <li v-for="(lang, i) in $i18n.availableLocales" :key="`Lang${i}`" :value="lang"> <a href="#" @click="setLocale('what should be placed here?')" ...

Exploring the capabilities of TabrisJs in conjunction with Upnp technology

Working with Upnp in TabrisJs seems to be a bit challenging. Even though it has good support for node packages, I am facing difficulties while dealing with Upnp. I included node-upnp-client in my package.json file. "dependencies": { "tabris": "^2.0 ...

How to Highlight Text in a textField Using Vuetify

Is there a way to dynamically set the value of a text field in Vuetify, focus it, and select its text? I encountered an error stating "select is not a function". This method works for regular text inputs but seems to be incompatible with Vuetify text fie ...

How to extract various arrays of identical objects from a larger array in JavaScript

I am working with an array containing objects of this structure: {id: 543, firstName: 'Ted', lastName: 'Foo', age: 32} My goal is to filter out objects in the array that have the same values for both the firstName and age properties. ...

What is causing the data to be altered outside of the directive scope?

I am having trouble understanding why the data is changing outside the directive in the external div. I expected it to behave the same as in the controller because the external Div is not wrapped in a directive or controller. Therefore, it should remain un ...

Is it necessary to configure modules using app.use in every route in express.js?

I recently learned that it is best practice to include the express module individually in each route file, rather than globally in app.js. Now I'm questioning whether I need to duplicate all the app.use statements in each route file or if I can just ...

Tracking the email field in a React form with refs

Hey there! I'm a music engineer working on my own personal website using React. I'm currently facing an issue with creating a contact form that allows users to input a subject in a text field, a message in a textarea, and then click a "reach out" ...

SyntaxError: An unidentified item was encountered at the <head> location

I have encountered an issue while loading a PHP file that utilizes ajax. Initially, the page loads without any errors. However, upon triggering the onclick event on a button, I receive the error message "Uncaught SyntaxError: Unexpected identifier" pointin ...

How to easily retrieve additional data and update a document using Meteor

I'm feeling a bit lost on the best approach for obtaining additional data, particularly using an API, and adding it to the existing list. Imagine we're implementing either an infinite scroll or a 'load more' button, when that action oc ...

node js retrieves information from the request body

Hey there! I'm diving into the world of Node.js and JavaScript, but I've hit a roadblock. I'm trying to fetch data from a URL using node-fetch, then parse it as JSON. However, I keep running into the issue of getting 'undefined' in ...

Stop the removal of the CSS content property

When a user enters and re-enters their password, I have a form that checks the strength of the password and displays text accordingly. However, I noticed that if a user makes a mistake and uses the backspace to re-enter the password, the text from data-tex ...

The Webstorm AngularJS extension appears to be malfunctioning, as it is not able to recognize the keyword 'angular'

As a beginner in Angularjs and web development, I have been using Webstorm to develop my projects. I have already installed the Angularjs plugin, which seems to be working fine in my HTML files. However, I am facing an issue with my .js file. In this file, ...

Is it better to utilize angular's $interval or a promise to execute code upon completion of an api call?

I am facing an issue with a slow api call in my code. $http.jsonp(url, { params: { 'client': 'translate_about', 'alpha': 1, 'hl': 'en' } }) .success(function (data) { ...

The class name is not defined for a certain child element in the icon creation function

Currently, I am developing a Vue2 web application using Leaflet and marker-cluster. I am encountering an issue with the iconCreateFunction option in my template: <v-marker-cluster :options="{ iconCreateFunction: iconCreateClsPrg}"> ...