【发布时间】:2020-06-17 06:03:39
【问题描述】:
我正在使用 Vuetify,但我似乎无法解决这个问题。我的<v-navigation-drawer> 中有一个<v-list>,看起来像这样:
SideDash.vue 组件
<template>
<v-navigation-drawer
v-model="drawer" clipped
:mini-variant.sync='mini'
width=240 absolute permanent
>
<v-list
flat dense nav class="py-1"
>
<v-list-item-group color='primary' mandatory>
<v-list-item
v-for="item in items"
:key="item.title"
dense
router :to="item.route"
>
<v-list-item-icon>
<v-icon>{{ item.icon }}</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-title>{{ item.title }}</v-list-title>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
</v-list>
</v-navigation-drawer>
</template>
<script>
export default {
data() {
return {
drawer: true,
items: [
{icon: 'mdi-speedometer', title:'Dashboard', route:'/dashboard'},
{icon: 'mdi-tools', title:'Tools', route:'/tools'}
],
}
}
}
</script>
路由器/index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import Dashboard from '@/views/Dashboard.vue'
import Tools from '@/views/Tools.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/dashboard',
name: 'dashboard',
component: Dashboard
},
{
path: '/tools',
name: 'tools',
component: Tools
}
]
const router = new VueRouter({
mode: 'history',
routes: routes
})
export default router
App.vue
<template>
<v-app>
<nav>
<Navbar/>
</nav>
<v-content>
<SideDash/>
</v-content>
</v-app>
</template>
<script>
import Navbar from './components/Navbar';
import SideDash from './components/SideDash'
export default {
name: 'App',
components: {
Navbar,
SideDash
},
data: () => ({
}),
};
</script>
这相当简单,直到我将道具:to="item.route" 添加到我的v-list-item 之前它运行良好。这使我的清单完全消失了。我最终得到了一个没有任何内容的导航抽屉,我不知道为什么。我在这里想念什么?感谢您的帮助
PS:这可能会有所帮助,但是当我在 App.vue 的 <v-content></v-content> 中添加 <router-view></router-view> 时,我得到一个空白页面,甚至没有我的导航栏或导航抽屉。我觉得它可能来自我的路由器设置。我签入了我的 package.json 并拥有它
"vue-router": "^3.1.3"
编辑
好吧,我发现了错误……这很愚蠢。在文件 main.js 中,import router from './router' 被注释为 router 在 new Vue(...) 中。我保留了此处显示的代码并且它有效。
【问题讨论】:
标签: vue.js vuetify.js vue-router