Child component in VueJs is undergoing a situation where the variable is found to be

Whenever an event is triggered, a function is called to populate a variable and open a modal from a child component. However, in the modal, the new variable appears empty initially. If I close and then reopen the modal, the data finally loads.

I have attempted to load the child component only after having the necessary data, but so far without success.

Parent

  <p class="open-modal-button" @click="openUpdatesModal">
     <i class="fas fa-sync"></i>
     Check for updates
  </p>

  <check-for-updates-modal
    v-if="check_for_updates_values.account_name != ''"
    :modalUpdatesOpen="modalUpdatesOpen"
    :check_for_updates_values="check_for_updates_values"
  />

  data() {
    return {
      //code....
      check_for_updates_values: [],
      modalUpdatesOpen: false,
    };
  }

openUpdatesModal() {
  this.temporaryChecker();
},

temporaryChecker() {
  this.check_for_updates_values.account_name = this.account_name;
  this.check_for_updates_values.company_registration_number = this.company_registration_number;
  this.check_for_updates_values.registered_address = this.registered_address;

  this.modalUpdatesOpen = !this.modalUpdatesOpen;
},

Child

<b-col>{{check_for_updates_values.account_name}}</b-col>

  props: [
    "modalUpdatesOpen",
    "check_for_updates_values",
  ],

  watch: {
    modalUpdatesOpen() {
      this.checkForChanges();
      this.$bvModal.show("modal-check-for-updates");
    },
  },

Answer №1

When initializing check_for_updates_values as an array, it can cause issues. It should actually be initialized as an object based on how you are using it.

Additionally, make sure to explicitly initialize all the keys in the object for Vue to properly register them for reactivity watchers. For example, if you have an empty data object like foo: {}, any new property added won't trigger a Vue refresh, such as

foo.label = 'test' // rendering issue
.

data() {
   return {
      check_for_updates_values: {
         account_name: null,
         company_registration_number: null,
         registered_address: null,
      },
   };
}

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

The function error is currently in a waiting state as it already includes an

I encountered a particular issue that states: "await is only valid in async function." Here is the code snippet where the error occurs: async function solve(){ var requestUrl = "url"; $.ajax({url: "requestUrl", succes ...

Obtain an identifier to be used as dynamic data in an ajax request with jQuery

I am struggling to extract the id from links that trigger the same ajax function. I have over 30 links generated dynamically, as shown below: <a href="javascript:void(0)" id="105">Item 105</a> <a href="javascript:void(0)" id="379">Item 3 ...

updating a d3js line graph in real-time using JSON information

Trying to wrap my head around dynamically updating a line graph with new data, shifting the graph to the left and adding fresh data from the right - you following me? Want it to behave just like the examples on I'm fairly new to d3 (javascript) and l ...

Showing information in Angular without using $scope

When working with Angular and angular UI-Router, my goal is to display content without relying on $scope. In my mainController, using directives like ng-repeat is no problem. However, I am struggling to access information from my postsController. Despite ...

The function of jQuery .click() not triggering on elements within msDropDown

I'm having difficulty implementing jQuery on an Adobe Business Catalyst site. The HTML snippet below shows the structure: <div class="banner-main"> <div class="banner-top"> <section class="banner"> <div class="catProd ...

What is the process of memory allocation for variables in Javascript?

Can you explain to me how local variables are allocated memory in JavaScript? In languages like C and C++, local variables are typically stored on the stack. Is this also the case with JavaScript, or are all variables stored in the heap? ...

Iterate over asynchronous calls

I am currently working with a code snippet that loops through an Object: for(var x in block){ sendTextMessage(block[x].text, sender, function(callback){ //increment for? }) } During each iteration, I need to make a request (send a Faceboo ...

Implement a dropdown menu in Vue.js using data fetched from an ajax request

I am looking to utilize ajax calls in conjunction with vue.js to dynamically populate the options for a drop-down menu. Here's an example of what I currently have: <select v-model="selected"> <option v-for="option in options" v-bind:valu ...

Utilizing the power of AngularJS in conjunction with the Edmunds Media API to retrieve stunning

Scenario: Utilizing a Rails application and $http.get in AngularJS to retrieve photos from the Edmunds.com MEDIA API. GOAL: To use ng-repeat to cycle through the vehicle photos. ISSUE: While I am able to successfully fetch a single image, I am struggling ...

Tips on adjusting a JavaScript animation function

I'm currently working on adjusting the animation function within the "popup" class that controls the gallery section of a website. When the page loads, an image and background start expanding from zero scale in the center to 100 VIEWPORT HEIGHT (VH) a ...

Loading Data in CodeMirror using XMLHttpRequest (XHR)

Is there any progress in loading the content into CodeMirror using XHR? ...

What causes jQuery to not work correctly during keydown events?

I've been working on this external jQuery code: jQuery(document).one('keydown', 'g',function (evt){ if ($("#tb").html() == "0") { $("#tb").html("Testing the chicken.") } else {$("#tb").html("Chickens fart too." ...

The issue with angular JavaScript in the child component is causing the left side navigation dropdown to malfunction

I'm currently facing an issue with the left side navigation in my home component. The dropdown functionality is not working within one of the routing modules (admin-routing.module.ts). Interestingly, the navigation works perfectly fine in app-routing. ...

Ways to utilize ng-options for looping through an array inside an object?

How do I utilize ng-options to fill a select element with the content of the "categories" arrays inside the objects? { title: "Star Wars", categories: ["Technology", "Adventure", "Coding"] }, { title: "Street ...

ReactJS Tutorial: Simple Guide to Updating Array State Data

const [rowData, setRowData] = useState([]); const old = {id: 'stud1', name: 'jake', room: '2'}; const newData = {name: 'jake', room: '3A'}; useEffect(() => { let ignore = false; ...

Top recommendations for implementing private/authentication routes in NextJS 13

When working with routes affected by a user's authentication status in NextJS 13, what is the most effective approach? I have two specific scenarios that I'm unsure about implementing: What is the best method for redirecting an unauthenticated ...

Running a code from a plugin in Wordpress site

I am currently utilizing the "wp-video-lightbox" plugin for WordPress, which generates small floating boxes for my videos. I am interested in incorporating variables like http://www.example.com/?video3 to provide shortcuts similar to what YouTube offers. ...

What could be the reason for StaticComponent constantly re-rendering despite having a static state that does not change

I'm trying to grasp the core concepts of how React triggers component re-rendering upon state changes. In the scenario described below, the console.log('hi') statement within the StaticComponent is executed every time the onChange event han ...

Is there a way to create a self-contained installation package for my Vue application?

Is it possible for my application to be downloaded and installed without requiring internet access after the download is complete? I am looking to create a standalone installer for this purpose. Are there any suggestions on how to go about implementing t ...

Declare a Nodejs variable as public

Here is my nodejs script to retrieve the current weather on a specific location using the command line. // Index.js // Required Modules const program = require('commander'); const clear = require('clear'); const chalk = require('c ...