我正在尝试通过 Vuejs 上的路由器链接将属性传递给组件,但该组件没有正确接收它们。我有一个主菜单和一个二级菜单,当单击主菜单按钮时,我想在其中传递属性:const Sidebar = { name:'sidebar', template:` <div> Sidemenu <router-link v-for="route in routes" v-key="route" :to="route">{{route}}</router-link> </div>`, props: { routes:{ type: Array, required: true, default: function(){return []} } }}const AppMenu = { name:'app-menu', template:` <div> <router-link :to="{name:'project', params:{routes: projectMenus}}">Project</router-link> <router-link :to="{name:'assets', params:{routes: assetsMenus}}">Assets</router-link> </div>`, data: function(){ return{ projectMenus: ['overview', 'settings'], assetsMenus: ['landscapes', 'characters'] } }}const App = { template:` <div> <app-menu/> <router-view name="sideview"/> <router-view name="sectionview"/> </div>`, components:{AppMenu}};const Routes= [ {path: '/', name:'home', redirect: 'project'}, {path:'/project', name:'project', components:{sideview:Sidebar}, props:{sideview:true}}, {path:'/assets', name:'assets', components:{sideview:Sidebar}, props:{sideview:true}}]Sidebar 组件正在渲染,因为我可以在页面上看到“Sidemenu”,但是控制台抛出[Vue warn]: Missing required prop: "routes" on Sidebar,所以我的子菜单链接没有显示。我搜索了文档,并在许多论坛中搜索了许多类似的问题,但找不到我做错了什么。
添加回答
举报
0/150
提交
取消