What is the best way to send information from a main blade to an included modal?

Trying to implement a functionality where a modal is triggered on clicking a button and an array named $incident is passed through to the properties of a Vue component. What is the correct way to pass data from a parent blade to an included modal? I initially tried using data-attach but it doesn't seem to work as expected.

The current setup involves looping through an incidents array in the blade file:

@foreach($incidents as $incident)
    <tr>
        <td>{{ $incident->service_now_incident_number }}</td>
        <td>{{ $incident->business_service_reference ?: 'N/A' }}</td>
        <td>{{ $incident->status }}</td>
        <td>{{ $incident->raised_date->format('d/m/y') }}</td>
        <td>{{ $incident->email }}</td>
        <td>
            <a class="btn btn-primary" data-toggle="modal" data-target="#incident-details-modal" data-attach="{{$incident}}">View</a>
        </td>
    </tr>
@endforeach

Below is the code snippet for the modal where the data needs to be passed:

<div class="modal fade" id="incident-details-modal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <incident-details :incident="{{$incident}}"></incident-details>
        </div>
    </div>
</div>

Is there a recommended approach to passing array data when the modal is loaded?

Answer №1

To achieve this, you can utilize the $emit method. The v-on directive is responsible for capturing events emitted by child components using $emit.

When the child component triggers a 'clicked' event:

export default {
  methods: {
    onClickButton (event) {
      this.$emit('clicked', 'someValue')
    }
  }
}

The parent component handles the 'clicked' event:

<div>
  <child @clicked="onClickChild"></child>
</div>

export default {
  methods: {
    onClickChild (value) {
      console.log(value) // someValue
    }
  }
}

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 border should not start at the left of the page; instead, I would like it to begin at the letter "T" in "Tech."

I am having an issue with the bottom border starting from the extreme left of the page. I want it to start from the letter "T" in Tech instead. #page-container { width: 1250px; margin: 0 auto; } h2 { font-weight: normal; padding-left: 15px; ...

Incorporate additional form element functionalities using radio inputs

Recently, I created code that allows a user to duplicate form elements and add values by clicking on "add more". Everything is functioning properly except for the radio inputs. I am currently stuck on this issue. Does anyone have any suggestions on how I c ...

Display a modal following a successful HTTP request

As I reflect on this code, I can't help but cringe at its ugliness. Forgive me for what you are about to see! The goal is to make an HTTP request using Axios and then display a modal confirming that an email has been successfully sent. Currently, th ...

example of reusing vue js component multiple times on a single page

Within my components, I am making an axios call. I have defined two of them with props that provide the URI for the axios call. export default { name: "CardData", props :['uri','suffixe' ,'label'], data : function (){ r ...

What is the expected output format for htmlspecialchars?

When I try the following: echo (htmlspecialchars("andreá")); I expect to see So, assuming that if I do echo (htmlspecialchars_decode("andreá")); I would get andreá. However, instead of the expected result, I see Additionally, when I run echo ...

Retrieve the id of the clicked hyperlink and then send it to JQuery

<a class = "link" href="#" id = "one"> <div class="hidden_content" id = "secret_one" style = "display: none;"> <p>This information is confidential</p> </div> <a class = "link" href="#" id = "two" style = "display: non ...

Using Javascript to access a website from a Windows Store application

Currently, I am working on a project to create a Windows store app using HTML and JavaScript. One of the key components of my app involves logging into a specific website with a username and password. Here is an example website for reference: The process ...

How does JSON.stringify data appear when embedded in the URL?

In order to transmit jQuery arrays to a PHP file as part of the $_POST data via an .ajax() call, I utilize the JSON.stringify method. The execution of the call is smooth and the expected data is retrieved. However, if I were to debug and manually input var ...

What are the steps to integrate MaterializeCss into Vue.js?

I prefer not to utilize Vue-Material or Vuetify. My choice is Materialize. Here's what I do: npm install materialize-css@next In my main.js file, where I define my new Vue App, I import Materialize like this: import 'materialize-css' Th ...

Set border-image to have rounded corners

I am attempting to create a circular button with a unique border effect. Here is the code I have implemented so far: body { display: flex; height: 100vh; overflow: hidden; justify-content: center; align-items: center; } button { height: 80px ...

Sending JSON data to Python CGI script

I've successfully set up Apache2 and got Python running without any issues. However, I'm facing a problem with two pages - one is a Python Page and the other is an HTML page with JQuery. Could someone guide me on how to correctly make my ajax p ...

displaying results on a webpage

Is there a solution for displaying a Linux shell output on a web page that allows for continuous updating without needing to start and stop the process each time? I require a network analyzer tool based on a shell that can run continuously, similar to comm ...

Is there a way to adjust the height of an image to be responsive in tailwind css?

<!-- this is the section with the services description and an image of an egg --> <!-- this is the first section with the description --> <div class="flex flex-1 flex-col items-center lg:items-start p-4"> &l ...

Achieving centered positioning for the 'row' class in Foundation 5, regardless of browser size

While viewing on desktop, the body is centered which is ideal. However, resizing the browser causes it to stretch to fit the full width and I want to avoid this. Regardless of the browser size, I want the first div with the "row" class to be centered with ...

Updates to the Tailwind file are not appearing on the page after reopening the file

Every time I reopen the project, the file tailwind properties do not get rebuilt and if I add new properties like text-color, they are also not reflected. Any suggestions on how to solve this issue? I need the project to update and take in new properties ...

Processing PHP response while waiting for jQuery AJAX call

I utilized an ajax function to transmit data. Within the PHP process, I executed phpmailer to send emails by using smtp gmail. The procedure proceeded smoothly, however, there are instances where I require informing the user to wait for the ongoing process ...

When the browser is refreshed, jQuery will automatically scroll the window down

I created a div that matches the height and width of the window to simulate a "home screen." When scrolling down to view the content, everything works fine. However, after refreshing the browser, it automatically scrolls back to where you were before. I wa ...

Generating HTML content using Angular 8 and JSON data

Currently, I am managing an Angular Storybook that consists of various components. Within the stories.ts file of a component, there is a JSON snippet containing properties such as the content of a DIV element, shown below... { "accordionLink": ' ...

Positioning the horizontal menu and footer links to the right side of the page

Struggling to get my menu and footer links aligned all the way to the right of the page. Here's what it currently looks like http://prntscr.com/32snbr, and this is the desired alignment http://prntscr.com/32snrm I've shared the HTML code below, ...

Vuejs components are not being rendered properly when using <router-view /> in Laravel 5.8

I am currently working on developing a Single Page Application (SPA) using Vuejs and Laravel. I have integrated vue-router to handle the routing within the application. However, I am facing an issue where the component that needs to be displayed inside the ...