Pass the identifier to another component in Vue

Connecting with the Community

Within my application, I showcase a list of doctors in the DoctorView component using the following code:

<div    
  class="col-12 m-2"
  v-for="recommendation in recommendations"
  :key="recommendation"
  >
   <DoctorListItem :recommendation="recommendation" />
 </div>

My goal is to enable users to click on an entry in the doctor's list and be directed to a detailed page about that specific doctor. To achieve this, I utilize a router-link within the DoctorListItem component:

<router-link
      :to="`/doctors/${recommendation.doctor.doctor_id}`"
      class="stretched-link"
    ></router-link>

The challenge I am facing now is passing this id to the ReadDoctorView component which displays comprehensive information about the selected doctor. While the necessary id is accessible in both DoctorView and DoctorListItem components, I struggle to pass it along to ReadDoctorView. I attempted using props but as a beginner, I am uncertain about how to define them and manage the data effectively.

In ReadDoctorView, I require a method similar to the one below to retrieve details for the selected doctor:

methods: {
     getDoctorById() {
       this.id = this.recommendation.doctor.doctor_id;
       console.log(this.id);
       return axios
         .get('http://URL/doctors/${this.id}')
         .then((response) => {
           this.doctordetails = response.data;
           console.log(id);
         })
         .catch((error) => {
          console.log("An error occurred: " + error.response);
         });
     },
  },

I hope my explanation clarifies my objective, and I appreciate any guidance you can offer.

Note: I am encountering warnings from vue router due to unfamiliar routes. Any suggestions on how to address these warnings would be greatly appreciated: https://i.sstatic.net/h0v0Y.png

Answer №1

You can access Vue router parameters by utilizing the $router object, give this solution a shot:

this.value = this.$route.params.value

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

Ways to display an array of objects based on their duplicate values

Struggling with the following example, seeking assistance new Vue({ el:"#app", data: { items: [ { type: "a", Descr: "searching" }, { type: "a", Descr: "maps" ...

What is the best way to set up distinct Jest test environments for React Components and Backend API routes within NextJs?

In the realm of testing with NextJS, Jest comes into play effortlessly, complemented by React Testing Library for frontend testing. Interestingly, Jest can also be utilized to test backend code. Currently, I am incorporating a library in my API routes tha ...

Ajax continues to repeatedly redirect to the PHP page

I currently have a Shopify store and I am looking to incorporate a form on the product page. However, I am facing an issue where when I try to submit the form using AJAX with an external link, it redirects to the external page instead of staying on the cur ...

I'm looking for a more efficient CSS solution to apply my :before & :after to all menu links collectively, rather than having to add them individually to each one

I have created a CodePen with a working hover effect using :before & :after on li link options. However, I am looking for a more efficient way to globally apply the position of these pseudo-elements without adding separate styles for each link option. ...

Working with content that includes Laravel Blade code in Vue.js

#SeekingHelp I need assistance with an issue I'm facing. My blog content includes syntax examples like {{ $title }} as it describes Laravel Blade. The Issue: When rendering my blog content on Vue.js, everything goes haywire due to the Blade syntax { ...

Issues occurred as the button's on-click function fails to execute the

Just starting out with JavaScript and coding, encountering a problem with an on-click scroll action that should go to another div. I've searched through several posts but still can't figure out why it's not working. Any assistance would be g ...

Using @react-three / react-three-fiber: Implement useLoader() to dynamically load a new file when props are updated

Presently, I have a functional react component that loads a gltf model during initial load. The path is passed through the props and this setup seems to be working well. However, when the props change and trigger a rerender of the component, I noticed tha ...

Dealing with errors in Vue components: What you need to know

Recently, I encountered an issue where a bug appeared in Chrome but worked fine in Firefox. The problem was with an upload component that looked like this: <input type="file" v-on:change="upload($event)"/> upload(e) { this.name ...

Attempting to set an access token as a variable in Node.js

As a newcomer to node.js, I'm encountering an issue while attempting to make Spotify API requests due to an error with my access token variable. The code I am using closely resembles the official example program provided by Spotify: var access_token ...

What is the process for switching the default font in Vuetify from Roboto to a different typeface for all elements?

Is there a way to update the font for all elements in Vuetify from Roboto to another option? I am currently using Vuetify, which comes with the default Roboto font. However, I would like to switch it to a different font. Modifying the font in the variable ...

Setting up a function in React to utilize an image stored in state

I have a function in my react component for image classification that retrieves the image from the img tag using document.getElementById: const img = document.getElementById('animal_image');. The image uploaded via the file input updates the sta ...

Is there a way to show an element on a website only when the height of the HTML content exceeds the height of the viewport?

My webpage serves as a dynamic to-do list, allowing users to add an endless number of tasks of all types. As the list grows in size, the page height increases and a scrollbar appears. Positioned at the bottom right corner of the page is a fixed button that ...

Outputs an excessive amount of [object Object] within a list instead of the expected values

My jquery code is causing some unexpected behavior. After entering text, the display only shows [object Object], however when I use console.log(areaname) the result is correct. I have tried stringifying the data but the issue persists $('#arealist& ...

A SyntaxError was caught due to an unexpected token '<' in the constants.js file when using react and vite

I'm trying to display a button in the sidebar with a name and an icon. I've been iterating through the list of categories, which are imported from the 'constants.js' file located in the utils folder. However, instead of getting the desi ...

The issue with React Testing using Jest: The domain option is necessary

I've recently developed a React app that implements Auth0 for Authentication. Right now, I'm working on setting up a test suite using Jest to test a specific function within a component. The function I want to test is createProject() in a React ...

Seeking assistance on transferring JSON values from one page to another - advice needed!

Here is a script used to parse the json value and display it on the first page (home.html). An href tag is used to navigate to the second page (Details.html). $(function() { var RETAIL_CRM = []; var dmJSON = "https://cordova.eu-gb.mybluemix.net/C ...

Tips for modifying VueJS's <slot> content prior to component instantiation

I am working with a VueJS component called comp.vue: <template> <div> <slot></slot> </div> </template> <script> export default { data () { return { } }, } </script> When I ...

When using NextJS with next-i18next and Firebase functions, all pages are redirected to a 404 error page if the locale is included

I have implemented next-i18next with Next.js in a setup that involves SSR deployed to Firebase functions. I followed the guidelines provided in this documentation https://github.com/i18next/next-i18next During development, everything functions correctly, ...

Trouble with JavaScript loading on blade bootstrap template

Greetings everyone! I'm currently in the process of developing a new web application using the Laravel framework. As a newcomer to Laravel & Blade, I've encountered some difficulties setting up my bootstrap template with blade. It appears that w ...

Developing advanced software platforms using HTML5/CSS/JavaScript, moving away from Adobe Flash

Recently, I embarked on a new software platform project using my own Java-made Application Server and Adobe Flash as the client-side technology. However, given that this project is long-term, I have realized that Flash is no longer a suitable option due to ...