Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda