What is the method for passing multiple parameters to a Vue.js component in Vue.js 2?

Here is how I have structured my view:

<table class="table table-inbox">
    ...
    <tbody>
    @foreach($messages as $message)
    <tr>
        ...
        <td>
            <div class="btn-group" role="group" aria-label="...">
                ...
                <a href="javascript:" @click="modalShow('modal-delete-message','{{ $message->id }}')" class="btn btn-danger">
                    <span class="fa fa-trash"></span> Delete
                </a>
            </div>
        </td>
    </tr>
    @endforeach
    </tbody>
</table>

@section('modal')
    <delete-message-modal id="modal-delete-message" :message-id="idModal"></delete-message-modal>
@endsection

My vue.js component (DeleteMessageModal.vue) looks like this:

<template>
    <div class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                ...
            </div>
        </div>
    </div>
</template>

<script>
    export default{
        name: 'DeleteMessageModal',
        props:['messageId'],
        methods: {
            deleteMessage(event) {
                var message_id = this.messageId
                console.log(message_id)
                ...
            }
        } 
    }
</script>

When the delete button is clicked, it sends the message ID to the DeleteMessageModal component.

I successfully display the value of the message ID using console.log(message_id).

Now, I also need to send additional parameters. In addition to the ID key in the messages array on the view, there are seller_id and buyer_id keys.

I want to send these keys to the vue components as well. How can I achieve this?

UPDATE

My updated solution :

This is how I modified my view:

<table class="table table-inbox">
    ...
    <tbody>
    @foreach($messages as $message)
    <tr>
        ...
        <td>
            <div class="btn-group" role="group" aria-label="...">
                ...
                <a href="javascript:" @click="modalShow('modal-delete-message','{{ $message->id }}#separator#{{$message->seller_id}}#separator#{{$message->buyer_id}}')" class="btn btn-danger">
                    <span class="fa fa-trash"></span> Delete
                </a>
            </div>
        </td>
    </tr>
    @endforeach
    </tbody>
</table>

@section('modal')
    <delete-message-modal id="modal-delete-message" :message-data="idModal"></delete-message-modal>
@endsection

The Vue.js component (DeleteMessageModal.vue) has been updated accordingly:

<template>
    <div class="modal" tabindex="-1" role="dialog">
...

Answer №1

To include additional information, you have the option to add props:

<script>
    export default{
        name: 'DeleteMessageModal',
        props:['messageId', 'buyerId', `sellerId `],
        methods: {
            deleteMessage(event) {
                var message_id = this.messageId
                console.log(message_id)
                ...
            }
        } 
    }
</script>

You can then pass these props in the parent template:

<delete-message-modal id="modal-delete-message" :message-id="idModal" buyer-id="123" seller-id="32"></delete-message-modal>

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

Utilizing Loading Icons in VueJS to Enhance User Experience During Asynchronous Database Operations

Looking for guidance on how to implement a loading icon in VueJS when the required data is not yet available. Any tips or suggestions on this topic? Your assistance would be greatly appreciated. ...

Animations of bezier curves created with Three.js

UPDATED: SOLUTION FOUND I am in need of guidance on how to create animation for the movement of points along a curve to simulate string motion in 3D while keeping performance in mind. Imagine multiple strings between two points, for example. Check out t ...

Using the push method on a global object array will replace all existing values within the array

After researching various solutions to this issue, I have not been successful in implementing the commonly suggested fix. The variable evtList holds a collection of global objects labeled as "Event". Previous discussions advised creating a local object ( ...

Differentiate the selected level on the DOM

Can someone help me with the following selector? $('#navigation ul li a').click(function(evt) {} It gets the elements I need, but also retrieves child elements. For example, it also selects: #navigation ul li li a // extra li I am curious a ...

A straightforward method of transmitting data from JavaScript to the Python back-end within a Streamlit application

Utilizing the st.components.v1.iframe, I integrated an authentication system that sends a token back to the parent when a user is authenticated. The iframe content is as follows: <script src="remote/auth.js"></script> <scri ...

Set up a single array containing multiple objects in a table, each with its own unique set of keys

I am currently developing an application that retrieves data from one or multiple databases, each with different names and varying numbers of columns. The goal is to consolidate this data into a single report screen and export it as a table. While the tabl ...

Is the data set in stone, or is it just the API data that can

Recently, I embarked on the journey of creating a blog using nextjs, MongoDB, and express. Taking advantage of getStaticProps and getStaticPaths, I was able to dynamically generate pages for each blog post and display them individually. However, I encoun ...

Cannon.JS ensures that walls are impenetrable

I am currently experimenting with three.js and cannon.js, but I have encountered an issue where I am unable to create solid walls or any stationary objects that can block the player's movement. Below is the code I have been working on so far. I would ...

Data input via $_POST method during the submission of a web application is failing to

Having trouble with the login functionality in an EllisLab application framework. The data from the $_POST method is not being stored upon form submission, resulting in an error message. When using var_dump($POST), it shows array(0){}. View Error Screensh ...

Switch up color scheme on table with checkbox activation

I'm currently using the AdminLTE template (Bootstrap) and I'd like to modify the color of the table row when my checkbox is checked. <table id="example1" class="table table-bordered table-striped dataTable" aria-describedby="example1_info"> ...

Ways to Achieve the Following with JavaScript, Cascading Style Sheets, and Hypertext

Can someone help me convert this image into HTML/CSS code? I'm completely lost on how to do this and don't even know where to start searching for answers. Any assistance would be greatly appreciated. Thank you in advance. ...

Using AngularJS to dynamically bind data based on certain conditions

I am managing an array of tasks that each have titles and labels. function Task(taskTitle, taskType) { this.title = taskTitle; this.type = taskType; } $scope.tasks = []; As I create different tasks with various types and add them to the array. In ...

Navigating the DOM upwards using D3 and CSS to make targeted selections

In my HTML code, I have a structured calendar representation as follows: <table> <thead>...</thead> <tbody> <tr>...</tr> <tr> <td day="4">...</td> <td day="5">...</td& ...

``Converting objects to key-value pairs in JavaScript like Scala's `toMap

Is there a more idiomatic JavaScript solution for this situation: const addTuple = (map, tuple) => { map[tuple[0]] = tuple[1]; return map; }; I am looking to refactor this example (refer to finance3.js) in a more functional style: angular.module(&apo ...

The responsive grid in bootstrap-vue can sometimes cause content to be concealed

I am in the process of creating a vue application using bootstrap-vue. Here is a snippet of my template and styles: <template> <div> <b-container class="p-0 mt-3" fluid> <b-row style="height:110px"> ...

Issue with JQuery Ajax call within If condition

My Ajax call is working perfectly in one scenario, but not in another when placed inside an if statement. I'm relatively new to JS and Ajax, so I may be missing something fundamental. Any insights would be appreciated. Thank you. The function that wo ...

Developing an ASP application using the MVP pattern to return JSON data can be transformed into a S

I’m looking to incorporate the following code into a sails js Controller public JsonResult GetEvents() { //Using MyDatabaseEntities as our entity datacontext (refer to Step 4) using (MyDatabaseEntities dc = new MyDatabaseEntities()) { ...

Leverage the power of JavaScript to bring in a JSON file

Currently, I am working on building a website and utilizing a json file to store the necessary data for one of the pages. However, I am encountering difficulties when attempting to successfully import the data. My coding platform is repl.it. My attempts s ...

Tips for transferring variables to my callback function or something similar

I'm facing a challenge with passing the markersArray to the callback function in order to push the results into the relevant array. The issue arises when trying to request nearby amenities for each filter and store them in separate arrays as per the c ...

"Enhance User Interaction with a Bootstrap Popup when Submitting Form Data via

As a junior web master, I have a simple question to ask. I have created a single page application for a client with a contact form at the end of the page. The validation is done using Bootstrap, but the only method I know to send the form data to a mail id ...