vue动态路由传参给组件为什么不显示默认

<!-- Argu.vue -->
<template>
  <div class="argu">
    <h1>{{name}}</h1>
  </div>
</template>

<script>
export default {
  props: {
    name: {
      type: String,
      required:true,
      default: "chj"
    }
  }
};
</script>
//对应的路由配置
{
    path: "/argu/:name",
    component: () => import("../views/Argu.vue"),
    props:true    
}

代码如上。
为什么访问/argu这个路径的时候组件不显示chj呢?

阅读 2.8k
2 个回答

参考链接: https://router.vuejs.org/zh/g...

/argu 没带 props ,所以访问不到 Argu 组件,如果想 /argu 能访问到

const Parent = {
    template: '<router-view></router-view>'
}
// 路由配置:
{
    path: "/argu",
    component: Parent,
    children: [
        {
            path: '',
            component: () => import("../views/Argu.vue"),
        },
        {
            path: ':name',
            component: () => import("../views/Argu.vue"),
            props:true  
        }
    ]  
}

访问/argu这个路径的时候,组件component: () => import("../views/Argu.vue"),都没有生成吧

至少访问/argu/123123123123

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题