Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
Passing vue.js Route Params to Component

I'm having trouble getting a route param to pass directly into a component. I followed multiple sets of directions in the docs (including using the Composition API as in the following code), but I'm still getting undefined when the CourseModule.vue first renders.

Route Definition

  {
    path: '/module/:id',
    name: 'Course Module',
    props: true,
    component: () => import('../views/CourseModule.vue'),
  },

CourseModule.vue:

<template>
    <div class="AppHome">
        <CustomerItem />
        <CourseModuleItem :coursemodule-id="this.CoursemoduleId"/>
    </div>
</template>
<script>
import { useRoute } from 'vue-router';
import CustomerItem from '../components/customers/customer-item.vue';
import CourseModuleItem from '../components/coursemodules/coursemodule-item.vue';

export default {
  setup() {
    const route = useRoute();
    alert(`CourseModule.vue setup: ${route.params.id}`);
    return {
      CoursemoduleId: route.params.id,
    };
  },
  components: {
    CustomerItem,
    CourseModuleItem,
  },
  mounted() {
    alert(`CourseModule.vue mounted: ${this.CoursemoduleId}`);
  },
};
</script>

coursemodule-item.vue:

<template>
  <div id="module">
    <div v-if="module.data">
      <h2>Course: {{module.data.ModuleName}}</h2>
    </div>
    <div v-else-if="module.error" class="alert alert-danger">
      {{module.error}}
    </div>
    <Loader v-else-if="module.loading" />
  </div>
</template>

<script>
import Loader from '../APILoader.vue';

export default {
  props: {
    CoursemoduleId: String,
  },
  components: {
    Loader,
  },
  computed: {
    module() {
      return this.$store.getters.getModuleById(this.CoursemoduleId);
    },
  },
  mounted() {
    alert(`coursemodule-item.vue: ${this.CoursemoduleId}`);
    this.$store.dispatch('setModule', this.CoursemoduleId);
  },
};
</script>

The output from my alerts are as follows:

CourseModule.vue setup: zzyClJDQ3QAKuQ2R52AC35k3Hc0yIgft

coursemodule-item.vue: undefined

CourseModule.vue mounted: zzyClJDQ3QAKuQ2R52AC35k3Hc0yIgft

As you can see, the path parameter works fine in the top level Vue, but not it's still not getting passed into the component.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

your kebab-cased :coursemodule-id props that you're passing to the CourseModuleItem component becomes a camelCased coursemoduleId props

Prop Casing (camelCase vs kebab-case)

try this

// coursemodule-item.vue
...
props: {
  coursemoduleId: String,
},
...
mounted() {
  alert(`coursemodule-item.vue: ${this.coursemoduleId}`);
  this.$store.dispatch('setModule', this.coursemoduleId);
},
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!