How can I use VueJS and Vue Router to generate a details page for a list item?

I am currently working with a list of items sourced from a JSON file and looping through them. However, I want to create individual details pages for each item using VueRouter.

Any advice on how I can accomplish this? I am facing difficulties in passing the data to the template of the details page.

Thank you

    <ul>
    <li v-for="project in projects.projects">
    {{ project.name }}
    <router-link :to="profileLink" class="button is-outlined">View Details</router-link>
    {{ project.coding }}
    { project.design }}
    {{ project.description }}
    </li>
    </ul>

Answer №1

Check out these helpful links:

If this fits your situation, here's what you can do:

  1. Add a new named route named details:

        {
          path: '/project/:projectId/details',
          name: 'details',
          component: Details,
          props: true,
        }
    

    Whenever you want to redirect a user to the details page, use this route. The :projectId is dynamic, so you can provide any id and it will always redirect to the Details component to display project details.

  2. Create a new router link in your list like this:

    <router-link :to="{ name: 'details', params: { projectId: project.id }}">{{project.name}}</router-link>
    
  3. In your Details component, make sure to declare route params as props, for example props: ["id"],. You can then access it in your component using this.id.

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

Hydrate a SSR VUE application to some extent

We are currently working on a website that unfortunately features numerous advertisements. Our plan is to utilize VUE for building the site, implement server side rendering, and then hydrate it on the client side. The issue lies in the fact that these adv ...

Description for script tag in HTML body

How can I embed a GitHub gist on my website using the script tag? I currently use the following code: <script src="https://gist.github.com/uname/id.js"></script> I've been wondering if there is a way to add alt text in case the gist fail ...

Executing a JavaScript function through a hyperlink created by an AJAX request

Having a JavaScript function here. I am performing an AJAX call, and within the received content, there is a link that needs to trigger the JavaScript function. MyJavascriptFunction(bla){ alert (bla); } ...

Invoking an *.aspx method from an external HTML file

Greetings, I am a newcomer to the world of web application development. I have successfully created an *aspx page that communicates with a webservice through a method returning a string. My next goal is to invoke this aspx method from a remote HTML 5 page ...

NiFi utilizes string manipulation functions such as padRight within JoltTransformJSON

Is it possible to utilize string manipulation functions like the example below in JoltTransformJSON? ${BIG:padRight(5, '@')} Reference: Expected Result: BIG@@ Similar to: "small_toUpper": "=toUpper(@(1, small))", "BI ...

Obtain information from local server in a React Native application

I am attempting to retrieve data from my localhost using React Native. My database, named "test," was created using MySQL. The table within the database is named "users" and contains the following rows: picture The connections are established in the ...

How can we effectively implement conditional rendering when dealing with components that are nearly identical?

Depending on whether the user is a professor, student, or not logged in, I render different landing pages. The landing pages are quite similar, with the only distinction being the buttons displayed. While I could easily achieve this using inline conditions ...

Exploring ways to retrieve the parent property name within System.Text.Json.Serialization.JsonConverter

Working with a 3rd Party API that provides data in the following format: { "dynamicFields": { "prop1": "val1", "prop2": "val2", "prop3": "val3" }, // otherFields ... } ...

Looking for some advice on tackling this JavaScript challenge - how can I effectively split an array?

Hello everyone, I recently started learning javascript and I'm facing a challenge with the following problem. Below is the code I've written so far and I would greatly appreciate any feedback on where I may be going wrong and how I can solve this ...

Troubleshooting MongoDB and Node.js: Issue with updating variables when inserting documents in a loop

As a newcomer to MongoDB, I'm facing a puzzling issue that has left me confused. In my dataset, I have an array of Employee objects structured like this: { "Name" : "Jack Jackson", "Title" : "Senior Derp Engineer", "Specialties" : [ "Kicki ...

I am facing difficulties with deploying my Next.js App on Vercel. Whenever I try to deploy, I encounter an error stating that the Command "npm run build" exited with 1

Hey there! I'm currently following a tutorial by JavaScript Mastery on Next.js (big shoutout to you, sir). I've been trying to deploy it on Vercel, but running into some deployment issues and having trouble testing out different tutorials. Here&a ...

Use jQuery to swap out two div classes within a table cell (TD) if they are

Although I'm making progress, I must confess that jQuery and CSS are not my strong suits. The objective: To create a dynamic div within a table data cell for a calendar feature. The content of the div varies based on the date range input. A filled d ...

ExpressJS does not support the 'Save' function

Working on a ticketing API using NodeJS + ExpressJS. Encountering an error when trying to modify a previously created ticket using the PUT method. Error /home/ismael/projects/nodejs-ticketing/routes/ticket.js:38 item.save(function(err){ ...

Bootstrap Progress Animation Not Scaling Properly

I am encountering an issue with my Bootstrap 2.3 progress bars. They are supposed to show async file reads and be animated by updating their CSS properties using jQuery. However, the problem I'm facing is that the scale seems to be off - when the prog ...

Using Page.ResolveClientUrl in JavaScript or jQuery allows for easy resolution of client

I find myself in a predicament where I need to choose between using an HTML page instead of a .aspx page for performance reasons. Currently, I am using an aspx page solely because of the CSS and javascript file paths like: <script type="text/javascript ...

Set YouTube Playlist to start from a random index when embedded

I've been trying to figure out how to set my embedded playlist to start with a random video. Here's what I attempted: <iframe src="https://www.youtube.com/embed/videoseries?list=PLPmj00V6sF0s0k3Homcg1jkP0mLjddPgJ&index=<?php print(ran ...

Learn how to efficiently execute a function multiple times using pure JavaScript

I am trying to create a tabbed content functionality with multiple elements. How can I utilize the same function for various elements declared in a variable? For example, I want to clone the parent div.tabs element with similar content but different ids an ...

What causes the appearance of 'GET/ 304 --' in my code? (vue.js, express)

While attempting to fetch data on the client-side using axios in vue.js, I encountered a server-side error with the code 'GET/ 304 --' The reason for this occurrence is unclear to me and I am unsure of how to troubleshoot or resolve it. If I re ...

I am attempting to develop a basic express application, but it doesn't appear to be functioning as expected

I am currently working on developing a straightforward express application. However, I am facing network errors when trying to access it through my browser at localhost:3000 while the application is running in the console. The root cause of this issue elud ...

Constructing an Http Post URL with form parameters using the Axios HTTP client

I need assistance in creating a postHTTP request with form parameters using axios on my node server. I have successfully implemented the Java code for constructing a URL, as shown below: JAVA CODE: HttpPost post = new HttpPost(UriBuilder.fromUri (getPro ...