Navigating through layers of nested data in Vue.js and assigning values to a multi-layer JSON object can be tricky

In my Vue component childEle, there is a complex form structure stored in the data:

data:{
  form:{
    root1:Number,
    root2:{
      child1:[],
      child2:{},
      child3:String
    },
    root3:[],
    root4:{
      child4:string,
      child5:[]
    }
  }
}

This JSON Object is tightly bound to the form in iView, making it challenging to flatten. I need to initialize values for this form when opening the component (a Modal). To achieve this, I pass values from the parent element using props:

props:{
  outForm:{
    type:Object,
    default: function () {
      return {}
    }
  }
  ……
}

I then watch for changes in the outForm prop:

watch:{
  outForm(val){
    this.form = val
  }
}

However, an issue arises. I also have a value attribute that controls the visibility of the Modal. When I update the value attribute, the corresponding value in data remains unchanged, preventing the Modal from closing even after calling this.$forceUpdate(). How can this be resolved? Thank you for your assistance!

Answer №1

To improve the flexibility of your modal component, consider moving the control logic for showing or hiding the modal to the parent component.

One approach is to treat the modal as always active and manage its visibility using a conditional statement like v-if in the parent component, linked to a variable such as showModal.

In this setup, the parent component changes the value of showModal to true when the user triggers an action to show the modal. Conversely, the modal emits a 'close' event (this.$emit('close')) which is caught by the parent component (

<child-component @close="hideModal" />
), setting showModal back to false.

If you find it necessary to store the visibility state within the modal component itself, you may want to explore the concept of reactivity further by referring to resources like reactivity in depth.

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

Preserving the original "this" context while binding a callback for a React child

class Parent extends React.Component { constructor(props) { super(props) this.handleChildOnClick = this.handleChildOnClick.bind(this) } handleChildOnClick() { /* Here, I want to perform an action that involves both Child and Parent. ...

Animating computed values with VueJS transitions

I am looking to create an animated block of posts that can be filtered. When certain filters are applied, a computed method filteredPosts is triggered and assigned to a component like this: <block-article :posts="filteredPosts" /> Within my <blo ...

Presentation comparing ng-show and ng-hide efficiency

Introduction:- There may be some who opt to use ng-show instead of ng-hide="!true", while others choose ng-hide over ng-show="!true". Technically, the ng-hide directive is not necessary. However, Angular introduced it for a standard coding structure. Plea ...

Angularjs directive retrieves infowindow DOM element from Google Maps

In order to apply some style fixes to the Infowindow, I am trying to select the element with the class 'gm-style-iw'. This selection process is taking place within an angularjs directive. <div ui-view="full-map" id="full-map" class="mainMap c ...

Attempting to develop a filtering feature using ReactJS

Having some trouble with the if statement in my filter list function. Can't seem to figure out why it's not working properly. Here is the code snippet: filterList (event) { var updatedList = this.props.array; var filterText = this.stat ...

What steps can be taken to resolve the issue with Angular routing?

import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import {HomeComponent} from "./home/home.component"; import {SettingsComponent} from "./settings/settings.component"; ...

Counting JSON Models in SAP UI5

I am encountering a particular issue. Please forgive my imperfect English. My goal is to read a JSON file and count the number of persons listed within it. I want this result to be stored in a variable that is linked to the TileContainer. This way, whenev ...

What is the correct method for dynamically importing framer-motion in NextJS?

I am currently utilizing framer-motion in my NextJS project. My goal is to import {motion} using Next's dynamic import method. However, I am encountering difficulties as it does not seem to function properly. import { motion } from "framer-motion ...

Client.on facing issue with receiving data upon initial connection

Currently, I am utilizing the net module in order to establish a connection between my client and server. Below is the code snippet: const Net = require('net'); client = Net.connect(parseInt(port), host, function() { co ...

What methods are available to test my website across different browsers such as outdated versions of Internet Explorer like IE8?

Currently, I am working on Chrome with Windows 7 OS installed. However, Windows 7 does not support Internet Explorer 8. This is causing issues when trying to view my web pages in the IE8 version and older. How can I resolve this problem? I have attempted ...

Dealing with event handler duplication in Rails applications when using turbolinks and inline javascript

After scrolling through numerous online posts, I am still in search of a satisfactory solution to address the issue of Turbolinks + inline scripts. Although Turbolinks provides a pleasant experience that I don't want to relinquish, I often struggle w ...

Transform jQuery code into vanilla JavaScript

I'm struggling with converting this part of code from jQuery to plain JavaScript. I've documented everything in a JSFiddle as an illustration. The following is the script: $(".button").click(function () { $pageID = $(this).attr('name& ...

I prefer not to have the entire URL visible to me

function updateDate(day, month, year) { month += ""; if (month.length <= 1) month = "0" + month; document.location.href = "<?php $_SERVER['PHP_SELF'];?>?page=events&day=" + day + "&month=" + m ...

Disable default styling on <v-card-actions>

Currently utilizing Vuetify, here is a simple setup for a <v-card> component: <template> <v-card> <v-card-title>MyCard</v-card-title> <v-card-text></v-card-text> <v-card-actions> <v-btn ...

Positioning elements at the bottom of the container

There is a dilemma that only those in the world of web development will understand. Beware! I have envisioned a layout for a website I am constructing. The concept involves tilted <hr/> elements on the page, with text wrapping around them (refer to ...

Issue with Angular ng-model not functioning as expected within ng-repeat block

Encountering an issue when trying to bind Json data into ng-model within ng-repeat. html : <div ng-controller="Ctrl"> <div> <table> <th> <td>add</td> <td>ed ...

Having trouble triggering a click event with JQuery

I have a hidden link for downloading Audio Files that I want the user to access using a button. However, I am having trouble triggering the click event. Below is the HTML code: <a class="APopupDown" data-icon="home" id="DownloadFile" href="http://yaho ...

Delete the item if the link uses Javascript: void(0)

<a class="slicknav_item" href="home">Home<span></span></a> <a class="slicknav_item" href="about">About<span></span></a> <a class="slicknav_item" href="javascript: void(0)">Services<span></span& ...

I just installed Electron on my Mac using the command 'sudo npm install electron -g', but now I am encountering an error. How can I resolve this issue

When I first attempted to run the command, I encountered 'Permission Denied' errors so I added sudo before the command as suggested. Another recommendation was to install the electron folder at /usr/local/lib/node_modules, but even after reinstal ...

Issue with accessing local server using NuxtJS 3 $fetch function

As someone who is new to Nuxt3, I recently attempted to establish a connection between my Nuxt3 frontend application and my backend site built with Laravel. The frontend URL is set at http://localhost:3000 while the backend can be found at http://localhost ...