Issue with passing data to Vue modal component

I am encountering an issue while attempting to pass data to the UserModal. Despite confirming that the value of the user_clicked field is assigned when the openuserdialog method runs (verified through console check), I am unable to pass it as an argument to the modal. Any assistance in resolving this problem would be greatly appreciated.

<v-data-table :items="users" :disable-initial-sort="true" :mustSort="true" hide-actions>
  <template slot="items" slot-scope="props">
   <td>{{ props.item.file_type.name }}</td>
   <td>{{ props.item.created_at | moment }}</td>
   <td><a @click="openUserDialog(props.item.id, props.item.user_type)" href='javascript:void(0);' class="details-link"><span class="hidden-xs-only">UserTypes</span><span class="hidden-sm-and-up">User Types</span></a></td>
  </template>
</v-data-table>
<v-dialog v-model="userDialog" max-width="1275">
 <UserModal :document="user_clicked" />
  <div class="text-xs-right">
    <v-btn class='vue-file-button text-right' @click="closeUserDialog" >Close</v-btn>
  </div>
</v-dialog>

<script>
  import UserModal from 'views/users/shortlisted_users.vue';
  export default {
    components: {
      UserModal
    },
    data: function() {
      return {
        userDialog: false,
        user_clicked: ''
      }
    }

    methods: {
     openUserDialog(document_id, user_type) {
        this.userDialog = true;
        this.user_clicked = user_type;
        console.log(this.user_clicked);
      },
      closeUserDialog(document_id) {
        this.userDialog = false;
      }
    }
</script>

Update 1

 openUserDialog(document_id, user_type) {
    this.user_clicked = user_type;
    this.userDialog = true;        
    console.log(this.user_clicked);
  }

Update 2

<template>
  <div>
    <v-card id="users-card">
        <Users :users="users"></Users>
    </v-card>
  </div>
</template>

<script>
import 'vue-awesome/icons';
import Icon from 'vue-awesome/components/Icon';
import Users from 'views/user/_user_table.vue';

export default {
  components: {
    Icon,
    Users
  },
  props: ['document'],
  data: () => ({
    users: [],
    tab_view: 'tab-users-card'
  }),
  created: function() {
    console.log(this.document);
    this.fetchUsers(this.document);
  },
  methods: {
    fetchUsers(document) {
      this.$axios.get('/my_account/users/document_suggested_users.json', {
        params: {
          document: document.id
        }
      })
      .then(response => {
        this.users = response.data;
      })
    },
  }
};
</script>

Answer №1

The issue arises when attempting to utilize the document in the created handler of the component, which is too premature in its life cycle.

An alternative approach involves implementing a watch handler within your UserModal as shown below:

watch: {
    document: function () {
        console.log(this.document);
        if (this.document) {
            this.fetchUsers(this.document);
        }
    }
}

Answer №2

To properly define your property, use the following syntax:

props: {
  fileData: Object
}

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

Determining the total number of combinations possible from a collection of five arrays containing items

I have five massive collections filled with various strings, and each of them contains a different number of elements. Below are examples of the lists: List 1 "Jeffrey the Great", "Bean-man", "Joe", "Charles", "Flamur", "Leka", ...

Interacting with an iframe within the same domain

I'm currently working on an application in Angular 6 that requires communication with an iframe on the same origin. I'm exploring alternative methods to communicate with the iframe without relying on the global window object. Is there a more effi ...

Vue.js - Inability to Access Data Property

I am facing an issue with my Vue.js 3 app. I am attempting to search through an array of objects within the app. You can find a fiddle showcasing the problem here. The problematic code snippet from the fiddle is as follows: async runSearch() { let search ...

Having trouble with my findIndex function in Node.js while working with a mongo DB database

I am having difficulty finding the index of a specific product in a MongoDB database. const cart = await this.model.findOne({ user: { $eq: user } }); if (cart) { const itemFound = cart.products.findIndex( (item) => item._id === ...

Using HTML and CSS to stack a DIV on top of another using z-index

I have 3 main layers on my website: 1) The main view with elements inside (#views in jsbin) - BOTTOM LAYER 2) An overlay (with a white background opacity of .8 #overlay in jsbin) - MIDDLE LAYER 3) A context menu (#contextmenu in jsbin) - TOP LAYER Wh ...

What is preventing ng-click from assigning a variable with the value from ng-repeat in AngularJS?

I'm currently working on a feature for an app that allows users to select font styles from Google Fonts for specific text elements. Here's the code snippet I have so far: <ul ng-init='headerFont="mono"'> <li ng-repeat=&apos ...

Displaying the array after input from the user has been loaded

Is there a way to capture user input from an HTML form and store it in an array using javascript? I want to then display the array as a list in a div tag in the HTML. Although my code is functioning, it seems to be outputting the text twice instead of jus ...

The combination of jQuery, using .load method in javascript to prevent scrolling up, making XMLHttpRequest requests, updating .innerHTML elements, and troubleshooting CSS/JS

While utilizing this code, CSS and Javascript are disabled (only HTML loads): function loadContent(limit) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4 && xhttp.status ...

Is it possible to make asynchronous calls to an external API without causing any drag on the overall speed of the website?

Currently, I operate an online store where at the end of the page, I integrate the eBay API with items related to the main product. Unfortunately, I have noticed that this integration causes a significant delay in the overall page loading by 4 to 10 secon ...

Converting a JSON object into an array of objects

I am looking to transform the following JSON structure let data = { item1: [11, 12, 13, 14, 15], item2: [16, 17, 18, 19, 20] } into this specific format using JavaScript's native functionalities of arrays or objects (compatible with all web brow ...

The heap limit has been reached in Github Actions, causing an allocation failure

Encountering a heap out of memory error in Github Action during the last "run: npm run build". FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory Error: Process completed with exit code 1. Showcasing the workflow file: name: ...

Is there a way to attach a hidden input to the file input once the jquery simpleUpload function is successful?

Attempting to add a hidden form field after the file input used for uploading a file through the simpleUpload call. Here is the HTML (loaded dynamically): <div class="col-md-6"> <div class="form-group"> ...

What are some techniques for obtaining the second duplicate value from a JSON Array in a React JS application by utilizing lodash?

Currently, I am tackling a project that requires me to eliminate duplicate values from a JSON array object in react JS with specific criteria. My initial attempt was to use the _.uniqBy method, but it only retained the first value from each set of duplicat ...

Implementing a Vue js waiting time counter for every item in an array

Let me provide some context: I have a table that displays incoming calls along with their waiting times. The data array is structured like this: [ { id: 1, patient_name: lorem ipsum, created_at: 2022-02-02 09:10:35, ... }, ...

Data not being returned by AJAX request

I'm currently working on implementing a script in the background of my PHP pages to periodically check for new messages in the database and notify users accordingly. To achieve this, I decided to utilize AJAX to make a call to a file containing the n ...

Using jQuery Plugin for Date Operations

I am in search of a jQuery tool that can assist me with date manipulations, such as: 1) Adding a specific number of days to a date and obtaining a new Date. 2) Determining the week of the year for a given date. 3) Calculating the number of days between two ...

Is it possible to utilize "this" in mapMutations spread within Vue instance methods?

Trying to define Vuex mutations like this: export default { props: { store: String }, methods: { ...mapMutations({ changeModel: `${this.store}/changeModel` }) } } Encountering an error message: An er ...

Can two Angular element components be utilized simultaneously on a single page in Angular 6?

Currently, I'm attempting to host independent Angular elements that can be seamlessly integrated into a non-Angular webpage. Everything works perfectly fine when there's only one element on the page, but as soon as I try to load two or more, I en ...

text box with an immobile header

As the browser window size decreases, the layout changes. However, when scrolling down, the search text box moves up and is no longer visible due to its lack of fixation. How can I make the search text box stay fixed as I scroll down? I tried implementing ...

Echo input and refresh on the current page upon submission

I am facing an issue with refreshing the page after submitting a form. I want to refresh the page so that the login attempt can be counted, but currently, the form is displayed without the page being refreshed to add to the count. This is my current code s ...