Implementing a separate detail view in Vuejs

I am currently working on a page with multiple cases. When I click on a case, the details for that case appear on the same page. Here is a screenshot of how it looks: https://i.sstatic.net/Y9S4J.png

As you can see in the screenshot, there are two cases listed - "ublox" and "test case". Clicking on either of them displays the details at the top of the page.

However, I want the details to be displayed on a separate page when a case is clicked. Since I am new to vuejs, I would appreciate any help in achieving this.

Below is my Vue.js code:

<template>

    <div>
        <!-- Code block goes here -->
    </div>

</template>

<script>

    // Vue.js script goes here

</script>

and here is my web.php file:

Route::get('/case-log/{id}', 'CaseLogController@index');

This is my Controller:

class CaseLogController extends Controller
{
    public function index($id)
    {
        $case = kase::with('sockets')->find($id);
        return $case->sockets;
    }
}

Your assistance in this matter would be greatly appreciated. Thank you in advance.

<template>

    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title"></h3>
            </div>
            <div class="card-body table-responsive p-0" style="height: 300px; width: 100%">
                <table class="table table-hover">
                    <thead>
                        <!-- Table header content goes here -->
                    </thead>
                    <tbody>
                        <!-- Table body content goes here -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</template>
<script>

    // Script for handling data fetching goes here

</script>

This has been updated:

<template>

    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title"></h3>
            </div>
            <div class="card-body table-responsive p-0" style="height: 300px; width: 100%">
                <table class="table table-hover">
                    <thead>
                        <!-- Table header content goes here -->
                    </thead>
                    <tbody>
                        <!-- Table body content goes here -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</template>
<script>

    // Script for handling data fetching goes here

</script>

Answer №1

To establish your routes with Vue-router, refer to the documentation for guidance on getting started.

Next, organize the details template into a component, such as DisplayDetailView.vue

Your structure will resemble:

DisplayDetailView.vue

<div class="col-lg-12">
  <div class="card">
      <div class="card-header">
          <h3 class="card-title"></h3>
      </div>
      <div class="card-body table-responsive p-0" style="height: 300px; width: 100%">
          <table class="table table-hover">
              <thead>
              <tr>
                  <th>ID</th>
                  <th>User Id</th>
                  <th>Case Id</th>
                  <th>Message Title</th>
                  <th>Process Type</th>
                  <th>Description</th>
                  <th>Data Load</th>
                  <th>Message Code</th>
                  <th>Log Type</th>
              </tr>
              </thead>
              <tbody>
              <tr v-for="list in lists">
                  <td>{{list.id}}</td>
                  <td>{{list.user_id}}</td>
                  <td>{{list.case_id}}</td>
                  <td>{{list.message_title}}</td>
                  <td>{{list.process_type}}</td>
                  <td>{{list.description}}</td>
                  <td>{{list.data_load}}</td>
                  <td>{{list.msg_code}}</td>
                  <td>{{list.log_type}}</td>
              </tr>
              </tbody>
          </table>
      </div>
  </div>
</div>

.....

Upon selecting a detail, you'll be directed to the relevant component displaying those details.

For instance, clicking on Ublox may entail associated code like this

ComponentWithCaseName.vue

<div class="col-lg-6">
    <div class="card">
        ...
      <tr v-for="kase in cases" :key="kase.id" v-on:click="handleCaseClick"> // add click handler
          <td>{{kase.name}}</td>
      </tr>
      ......
  </div>
</div>

The component with the case name clicked should have a corresponding method

methods: {
  handleCaseClick() { // navigates to the display view details component i.e DisplayDetailView.vue
    this.$router.push(`/path-to-component-for-view-details/${uniqueIdentifierToFetchTheDetailsFromTheDatabase}')
  }
}

Within the DisplayDetailView.vue component, extract the unique identifier from the URL using either the created or mounted hook (the example uses the created hook) to retrieve data from the database filling the template.

DisplayDetailView.vue

 export default {
    data() {
        return {
            cases: [],
            lists: [],
        }
    },
    created() {
    const uniqueIdentifierToFetchTheDetailsFromTheDatabase  this.$route.params.uniqueIdentifierToFetchTheDetailsFromTheDatabase 
       axios.get(`/case-log/${uniqueIdentifierToFetchTheDetailsFromTheDatabase}`).then(response => this.lists = response.data);
    },
 }

This provides an overview of the process, further information can be found here.

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

Using an array of references in React

I've encountered a problem where I'm trying to create a ref array from one component and then pass it to another inner component. However, simply passing them as props to the inner component doesn't work as it returns null. I attempted to fo ...

Decipher the JSON data for a Facebook cover photo

I am utilizing the Facebook Graph API to retrieve the user's cover picture. By accessing the link provided at , a JSON object containing the picture link is returned. How can I fetch this link using JQuery or JavaScript? Here is my attempt: HTML: & ...

Vue component not displaying object property

I am currently working on implementing a filter method in a Vue component. Here is the filter method I am trying to use: filterHotels:function(){ var thisHotels = this.hotelRoomArr; console.log(this.hotelRoomArr['107572']['rooms ...

Deliver the GWT module in JavaScript format

Currently, I am in need of the following: I need to create a GWT module that can be seamlessly incorporated into a GWT app without requiring recompilation - essentially a plug-and-play solution. This module should include a widget along with various cla ...

Determining the most appropriate time to utilize the 'async' built-in function in ES2017 versus implementing 'npm i async' can depend on a variety of factors such

I recently discovered that async/await is a feature of ES2017, however, in some of my previous projects I had to use the package async to implement async/await functionality. Is there a simple way to determine when async can be used without importing it? ...

The issue of Three.js SkinnedMesh jittering arises when it is distant from the scene's root (0,0,0)

In my current project, I am developing a third-person RPG style game using Three.js and Blender. The terrain in the game world is tiled and loops endlessly in all directions, triggered when the player object approaches defined edges along the z or x-axis. ...

Manipulate the visibility of a child element's dom-if based on a property retrieved from the parent element

Exploring the world of Polymer, I am eager to tackle the following scenario... I have a binding variable called {{readonly}} that sends data from a parent Dom-HTML to a child Dom-HTML in my Polymer project. The code excerpt looks something like this... C ...

Tips for creating read-only checkboxes with multipledropdown.js in Angular.js

I am trying to make all checkboxes in a multiple dropdown list readonly using Angular.js with the multipledropdown.js plugin. My code snippet is as follows: <div class="col-md-6" ng-show="sub_sub_menu"> <div class="input-group bmargindiv1 col-md- ...

When using the `.push` method, the array becomes null

Currently, I am in the process of developing an angular application. Within my component's .ts file, there exists an array structured as follows: public myArray = []; public dataFromAPI = []; In a particular method within this component, whenever I ...

Are you seeing a 'Connection refused! Is the selenium server started?' error while running VueJS Nightwatch E2E tests with ChromeDriver and Chrome?

My VueJS app is integrated with Nightwatch E2E tests. I recently set up user accounts and authentication, but now when I run the E2E tests, they fail inexplicably. Here is the output I receive: code/premium-poker-tools [master●] » npm run e2e > < ...

Best practices for aligning the widths of input-group-addon elements

Hey there, I'm working with an HTML file that has 3 input options. Here's a snippet: <script type="text/ng-template" id="dashboard_assigngroup_popup.html"> <div class="modal-header modal-header2"> <h3 class="modal-tit ...

How do I find out the properties of individual components in Material UI?

Learning material ui has been a challenge for me as I struggle to figure out the properties available for each component. For instance, in a tutorial on YouTube, they used the AppBar component like this: <AppBar title="Enter user details" /> But ho ...

Tips for handling 429 errors while using axios in a react native application

My React Native app is connected to a MongoDB database using Express and Node.js, with Axios handling client-server communication. The app frequently exchanges data with the database, sometimes up to 4 requests per second when in use. While everything wor ...

What is the best way to send an array of objects to a Node.js server?

What is the method for sending an array of objects with user data to the server for verification? I am attempting to pass orderform data to a server for validation and then display it on a different page after redirection. const addProductsToServer = (ev ...

The Coinbase Pay application fails to compile properly due to a missing Babel loader

Currently, I am working on integrating the coinbase pay sdk into my project. Although I have successfully created a button utilizing their provided examples, I am encountering an issue during the build process which seems to be internal to their SDK. Spec ...

Utilize the power of Bootstrap Modals to enhance your form validation with a seamless integration of Jquery

I have a few questions about JQuery syntax: 1) The modal is not showing up. Could this be related to an operator (&&) issue? How can I fix it? It should only appear if the input is valid. 2) How do I combine preventDefault with valid classes when submitt ...

Utilizing Express.js: Passing the req Object to Middleware without the Need for a New Multer Route

Hello to the Express.js and StackOverflow communities! I hope this question is not a duplicate, as I searched and found nothing similar. Currently, I am working on a project using Multer with Express to enable users to upload images, which will be saved a ...

The $scope object in Angular is supposed to display the $scope.data, but for some reason, when I attempt to access it

Having an issue with my controller that fetches data from a service. After receiving the data in the controller, I'm using $scope to pass it to the view. Strange behavior - console.logs inside the 'then' function display the data correctly ...

How can I designate the file name when using Ajax to export in Excel formatting?

Can you help me with the code to set a specific filename for downloading an Excel file? if(comp_id != "Select Company") { $.ajax({ url: 'includes/export.php', data: { action: 'compreport', 'comp':comp_i ...

Delete the placeholder image from a div once live content has been inserted into it

If I have a container div that displays an image when empty, but I want to remove the image when content is dynamically added to the container, what would be the most effective way to do this with jQuery? The usual method of checking if the container' ...