Vue.js Vue-未定义将参数作为道具传递到路由

Vue.js Vue-未定义将参数作为道具传递到路由,vue.js,vuejs2,vue-component,vue-router,Vue.js,Vuejs2,Vue Component,Vue Router,我正在将参数从组件传递到命名路由: <v-list-tile :key="team.logo_url" :to="{name: 'team', params: { id: team.id, name: team.name }}" avatar > 但组件在引用时不呈现道具: <template> <v-container>

我正在将参数从组件传递到命名路由:

      <v-list-tile
        :key="team.logo_url"
        :to="{name: 'team', params: {
          id: team.id,
          name: team.name
        }}"
        avatar
      >
但组件在引用时不呈现道具:

<template>
  <v-container>
      <p>{{ id }}</p>
  </v-container>
</template>

<script>

  import TeamService from '@/services/TeamService';

  export default {
    props: ['id', 'name'],
    data: () => ({
        players: [],
        games: []
    }),
    mounted() {
        console.log(this.id);
    }
  }
</script>

{{id}

从“@/services/TeamService”导入TeamService; 导出默认值{ 道具:['id','name'], 数据:()=>({ 玩家:[], 游戏:[] }), 安装的(){ console.log(this.id); } }
挂载方法中的日志返回未定义的

但是,当我查看Vue开发工具中的
TeamInfo
组件时,我可以看到两个道具都未定义,但参数都已填充


我希望能够使用组件中的道具,并使用团队ID填充URL。

您必须使用
布尔模式将参数传递给URL和道具。您还必须在
路径中定义参数才能访问它。下面是演示如何使用它的示例

{
  name: "team",
  path: "/team/:id",
  component: TeamInfo,
  props: true,
}

您必须使用的
布尔模式将参数传递给URL和道具。您还必须在
路径中定义参数才能访问它。下面是演示如何使用它的示例

{
  name: "team",
  path: "/team/:id",
  component: TeamInfo,
  props: true,
}

尝试了此操作,但无法解决问题。当我试图记录道具时,我仍然没有定义。我现在不太关心URL,因为更担心的是我无法将参数作为道具放入TeamInfo组件。您还必须使用
/team/:id
路径中定义参数,否则道具将不被考虑。我用一个例子更新了答案。是的,我这样做了。路径现在很好。但是无法从路径将道具放入组件中。您是否检查了我在答案中链接的示例?尝试了此操作,但没有解决问题。当我试图记录道具时,我仍然没有定义。我现在不太关心URL,因为更担心的是我无法将参数作为道具放入TeamInfo组件。您还必须使用
/team/:id
路径中定义参数,否则道具将不被考虑。我用一个例子更新了答案。是的,我这样做了。路径现在很好。但是无法从路径将道具放入组件。您是否检查了我在答案中链接的示例?