One way to transfer data from a Vue table component to another Vue table component is by including an edit button on each row in the table. This allows

When working with two table components, one fetching records using axios and the other needing to get records after clicking on the edit button in the parent component, I encountered issues. Despite attempting Vue's parent-to-child component communication method, it did not work as expected with the table.

<div><table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>Request NO</th>
                        <th>User name</th>
                        <th>Product</th>
                        <th>Requested Quantity</th>
                        <th>Approved Quantity</th>
                        <th>Status</th>
                        <th>Date</th>
                        <th>Action</th>
                    </tr>
                    </thead> <tbody>
                    <tr v-for="temp in reques " >
                        <td>{{temp.operation_id}}{{temp.user_id}}</td>
                        <td>{{temp.user_id}}</td>
                        <td>{{temp.product_name}}</td>
                        <td>{{temp.rquantity}}</td>
                        <td>{{temp.aquantity}}</td>
                        <td>{{temp.status}}</td>
                        <td>{{temp.created_at}}</td>
                        <td>
                            <div role="group" class="btn-group">
                                <button class="btn btn-info" @click="edit(temp)"
                                        type="button">
                                    <i class="fa fa-edit"></i>
                                </button>
                                <button class="btn btn-danger" type="button">
                                    <i class="fa fa-trash"></i>
                                </button>

                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>div class="col">
    <approved :form="form"></approved>
</div></div>

import VForm from 'vform'
import AlertError from "vform/src/components/AlertError";
import HasError from "vform/src/components/HasError";
import approved from "./approved";
import operationcreate from "./create" export default {
    components: {HasError, AlertError,
        approved,operationcreate,
    },
    data() {
        return {
            reques: [],
            here: [],
            form: new VForm({
                operation_id:'',
                product_name:'',
                rquantity: '',
                aquantity:'',
                status:'',
                created_at:'',
                user_id:''
            })
        }
    },
    methods:{
        edit(temp){
            this.form.fill(temp);
        }
    },
    created() {
        axios.get('/request-list')
            .then(({data}) => this.reques = data);
    }
}

The second table component:

 <div>
    <div class="card">
        <div class="card-header">
            <h3 class="card-title">Quick Access</h3>
            <div class="card-tools">
                <button type="button" class="btn btn-tool" data-widget="collapse">
                    <i class="fa fa-minus"></i>
                </button>
            </div>
        </div>
        <div class="card-body p-0">
            <table class="table table-bordered table-hover">
                <thead>
                <tr>
                    <th> Product Name</th>
                    <th> Request Quantity </th>
                    <th> Approved Quantity</th>
                    <th> Status</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="temp in form">
                    <td>1</td>
                    <td>{{temp.rquantity}}</td>
                    <td>{{temp.aquantity}}</td>
                    <td>{{temp.status}}</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

<script>
export default {
    props: ['form'],
    data() {
        return {

        }
    },
    methods: {},
    created() {

    }
}

Answer №1

After fetching data from an axios request in Table 1, you must emit an event so that the parent component can access it.

In Table 1:

created() {
        axios.get('/request-list')
            .then(({data}) => {
                this.reques = data
                this.$emit("dataRecieved",data)
             });
    }

This event will trigger in the component and can be accessed by the v-on (or @) in the parent component:

<table-component-1 @dataRecieved="updateTableTwo" ></table-component-1>

You need to initialize an empty object in the parent component and pass it as a prop to Table 2 until the data is received from the axios request:

<table-component-2 :myData="tableData" ></table-component-1>

The updateTableTwo() method in the parent component (the event parameter is passed by default):

updateTableTwo(event) {
   this.tableData = event
   //event will contain the data passed from Table 1
}

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

Tips for populating a dictionary with a large datalist of around 2000 items

Currently, I'm facing an issue where the code I'm using takes about 10 seconds to run on Chrome and around 2 minutes on IE11, which is the primary browser it will be used with. for (var key in dict) { if (dict.hasOwnProperty(key)) { ...

Sorting arrays can yield varying results depending on the browser being used

The variations in output between Chrome 70.0, Chrome 69.0, and Firefox 63.0 for the same code are puzzling. var arr = [1,2,43,1233,5546,33,6,11]; arr.sort(() => -1); //[11, 6, 33, 5546, 1233, 43, 2, 1] arr.sort(() => 1); //[1, 2, 43, 1233, 5546, 33, ...

Discovering the dimensions of a video in Angular 2 using TypeScript

To determine whether the video is portrait or landscape, I am attempting to retrieve the height and width of the video using the following method: import { Component, OnInit, AfterViewInit } from '@angular/core'; @Component({ selector: ' ...

Pace.js doesn't bother waiting for iframes to completely load before moving on

On my website, I am using pace.js but encountering issues with pages containing iframes. Is there a method to ensure that pace.js considers the content loading within those iframes? I attempted to configure paceOptions to wait for the iframe selector to l ...

Problem with z-index in VueJS: Child div z-index not functioning within v-dialog

I am facing an issue where I have brought a span to display a loading image inside the v-Dialog of a vuejs screen. The problem is that the v-dialog has a z-index of 220 set as inline style, causing my new span (loading image) to appear below the v-dialog. ...

Combining multiple JSON strings into a single object using JavaScript

I am facing an issue with parsing a JSON output that contains two strings with specific formats: [{"device_id":"9700015","update_time":"2017-01-04 18:30:00","sensor_value":"1287.6"}] [{"device_id":"9700016","update_time":"2016-12-31 18:30:00","senso ...

Show different material ui TextFields based on what the user chooses

My dropdown menu offers two options: BUY x AND y AND z SAVE m BUY n FOR m If I select option 1, I want to display Textfields for x, y, and z. If I choose option 2, then only Textfields for n and m should be displayed for user input. In the code snippet ...

Why is this regular expression failing to match German words?

I am attempting to separate the words in the following sentence and enclose them in individual span elements. <p class="german_p big">Das ist ein schönes Armband</p> I came across this: How to get a word under cursor using JavaScript? $(&ap ...

Exporting a named export for every HTTP method is the way to go with NextJs

I'm currently working on a project to create an Airbnb clone using NextJs. The tutorial I'm following is using an experimental version, while I've opted for the latest version of NextJs. One aspect that's been causing confusion for me i ...

How to dynamically add an input textbox after a selection change in YUI JavaScript?

Is there a way to add an extra input textbox after an onchange event in a selectbox using the YUI library? I need to utilize YUI and the form is generated with PEAR Quickforms lib. This is what I have so far: $form->addElement('select', &ap ...

Show the components only if the final digit in their identification number is less than i

I have several span elements with IDs like "tag1", "tag2", etc. I want to display only the spans whose ID ends with a number less than 19. These elements are part of a class called "notVis", which is hidden by default using $(".notVis").hide(); when the ...

Tips for concealing a dynamic table element in Angular 9

I have dynamically generated columns and rows in a table. Here is my HTML for the table component: <table id="tabella" class="table table-striped table-hover"> <thead class="thead-dark"> <tr> <th *ngFor="let header of _ob ...

What is the method to display just the final 3 characters within a paragraph?

Is there a way to display only the last three characters of a string using either a method or a string method? I consistently have a 13-digit number, but I specifically require showing only the final three digits. Appreciate any assistance provided. Than ...

What is the best way to display the nested information from products.productId?

How do I display the title and img of each product under the product.productId and show it in a table? I attempted to store the recent transaction in another state and map it, but it only displayed the most recent one. How can I save the projected informa ...

Verifying if a number is present in a textbox when inserting text (without using setTimeout)

I have an input field similar to the one shown below: <input type ="number" id="numberTxt" placeholder="Number Only"/> To ensure that the value entered is a number, I am using the following function with the keypress event: <script> ...

Adding the classname "active" in ReactJS can be achieved by utilizing the `className` attribute within

I am facing an issue with adding the active classname in my code. Can anyone suggest a solution to add the active classname for this section: <li onClick = {() => onChangeStatus({status: 'on-hold'})} className = {appState === {'status& ...

Tips for preventing a page from automatically scrolling to the top after submitting a form

Recently, I set up a form where users can input values. The form is set to submit either on change or when the user hits enter, depending on which value they want to update. However, after the values are submitted, the page automatically jumps back to the ...

What is the process by which Node can access predefined variables in clustering?

Consider the following code snippet: var running = false; var cluster = require('cluster'); if(cluster.isMaster){ cluster.fork(); running = true; } If this code is executed within multiple forks, would the value of 'running' ...

Unlocking the Secret Code

Presenting the question: checkPassword([["Peter", "P"], ["Sarah", "S"], ["Ethan", "R"]], {"Peter": "P", "Sarah": "Q", //"Ethan":"E"}) ...

Is it possible to show an image without altering the Box dimensions?

Hi there, I am currently working on designing a footer and I have encountered an issue. I want to add an image in a specific position, but when I do so, it affects the size of the box. I was wondering if there is a way to set the image as a background or b ...