我正在使用 Vuetify,我似乎无法解决这个问题。我有一个 <v-list>
在我的 <v-navigation-drawer>
看起来像这样:
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(...)
。我保留了此处显示的代码并且它有效。
原文由 JrmDel 发布,翻译遵循 CC BY-SA 4.0 许可协议
关于为什么
:to
方法有效,但@click
方法无效的任何建议?作品
没有