我正在构建一个与Vuex和vue-router相结合的Vuetify应用程序。一些视图使用默认的导航抽屉,但另一些视图在其导航抽屉中有不同的项目。This documentation say我可以通过道具来查看组件。所以我像这样实现它:
routes/index.js
{
path: '/courses/:courseId/lessons/:lessonId',
name: 'Course 1',
components: {
default: () => import('@/views/ViewLesson.vue'),
sidebar: () => import('@/components/CourseNavBar/CourseNavBar.vue')
},
props: {
items: [
{ text: "Link 1", href:"/link1" },
{ text: "Link 2", href:"/link2" }
]
}
}src/App.vue
<template>
<v-app>
<v-app-bar
app
color="primary"
dark
>
<h1>My Project</h1>
</v-app-bar>
<v-navigation-drawer><router-view :items="items" name="sidebar"/></v-navigation-drawer>
<v-content>
<router-view />
</v-content>
</v-app>
</template>但很明显,
src/组件/CourseNavBar.vue
<template>
<!-- <v-navigation-drawer :value="1"> -->
<v-list dense>
<navbar-item v-for="(item, i) in items" :key="i" :item="item" >
{{ item.text }}
</navbar-item>
</v-list>
<!-- </v-navigation-drawer> -->
</template>
<script>
import NavBarItem from './NavBarItem.vue'
export default {
props: {
items: Array
},
components: {
'navbar-item': NavBarItem
}
}
</script>但是<CourseNavBar>的道具仍然没有定义,我到底做错了什么?
发布于 2020-02-26 23:48:50
有一些问题..。
用:替换= ...
items: [
{ text:"Link 1", href:"/link1" },
{ text:"Link 2", href:"/link2" }
]并且sidebar组件(不是路由器视图)应该在navigation-drawer的插槽中...
<v-navigation-drawer><sidebar :items="items"></sidebar></v-navigation-drawer>发布于 2020-02-27 01:43:02
在您的routes\index.js中,您需要为每个命名视图定义属性选项:
{
path: '/courses/:courseId/lessons/:lessonId',
name: 'Course 1',
components: {
default: () => import('@/views/ViewLesson.vue'),
sidebar: () => import('@/components/CourseNavBar/CourseNavBar.vue')
},
props: {
default: true,
sidebar: true,
items: [
{ text: "Link 1", href: "/link1" },
{ text: "Link 2", href: "/link2" }
]
}
}根据@Zim所说,在将href值赋给props item数组时,您使用了"=“而不是":”。
您可以使用<router-view name="sidebar"/>来输出命名的组件。
https://stackoverflow.com/questions/60415249
复制相似问题