vuetify.js - vuetify 路由器链接不适用于抽屉儿童
问题描述
我正在开发 vuetify 抽屉,当我单击每个抽屉时,它会导航到另一个页面,所以我认为如果我为每个抽屉添加一些子项会很酷,但是之后当我单击每个子项时,它会导航到错误的页面.
在添加儿童之前的抽屉代码......工作正常的那个
data: () => ({
items: [
{
icon: 'mdi-view-dashboard',
title: 'Dashboard',
to: '/',
},
{
icon: 'mdi-account',
title: 'First',
},
{
icon: 'mdi-account',
title: 'Second',
to: '/pages/mesebo',
},
],
}),
computed: {
...mapState(['barColor', 'barImage']),
drawer: {
get () {
return this.$store.state.drawer
},
set (val) {
this.$store.commit('SET_DRAWER', val)
},
},
computedItems () {
return this.items.map(this.mapItem)
},
profile () {
return {
avatar: true,
title: this.$t('avatar'),
}
},
},
methods: {
mapItem (item) {
return {
...item,
children: item.children ? item.children.map(this.mapItem) : undefined,
title: this.$t(item.title),
}
},
},
路由器代码
export default new Router({
mode: 'hash',
base: process.env.BASE_URL,
routes: [
{
path: '/',
component: () => import('@/views/dashboard/Index'),
children: [
// Dashboard
{
name: 'Dashboard',
path: '',
component: () => import('@/views/dashboard/Dashboard'),
},
// Pages
{
name: 'First',
path: 'pages/burea',
component: () => import('@/views/dashboard/pages/Bureau'),
},
{
name: 'Second',
path: 'pages/mesebo',
component: () => import('@/views/dashboard/pages/Mesebo'),
},
],
},
],
})
添加孩子后的抽屉代码
data: () => ({
items: [
{
icon: 'mdi-view-dashboard',
title: 'Dashboard',
to: '/',
},
{
icon: 'mdi-account',
title: 'First',
children: [
{
title: 'sub-first',
to: '/pages/bureau',
},
],
},
{
icon: 'mdi-account',
title: 'Second',
to: '/pages/mesebo',
children: [
{
title: 'sub-second',
to: '/pages/mesebo',
},
],
},
],
})
computed: {
...mapState(['barColor', 'barImage']),
drawer: {
get () {
return this.$store.state.drawer
},
set (val) {
this.$store.commit('SET_DRAWER', val)
},
},
computedItems () {
return this.items.map(this.mapItem)
},
profile () {
return {
avatar: true,
title: this.$t('avatar'),
}
},
},
methods: {
mapItem (item) {
return {
...item,
children: item.children ? item.children.map(this.mapItem) : undefined,
title: this.$t(item.title),
}
},
},
我没有更改 router.js 文件,我唯一做的就是将“to:'/pages/bureau'”从以前的位置变为子级,但是当您查看屏幕截图时,它正在进入到另一个未定义的链接,我使用的模板是。https://demos.creative-tim.com/vuetify-material-dashboard/
解决方案
您需要做的是,添加属性“组”并将其分配给组件的文件夹,在这种情况下,您的组将是“页面”,而您的“到”属性将是“/bureau”,因此在您的抽屉上更改此
{
icon: 'mdi-account',
title: 'First',
children: [
{
title: 'sub-first',
to: '/pages/bureau',
},
],
},
进入这个
{
icon: 'mdi-account',
title: 'First',
group: 'pages',
children: [
{
title: 'sub-first',
to: '/bureau',
},
],
},
推荐阅读
- variables - Variable name doesn't work for init_from_checkpoint?
- php - calling stored procedure twice returning same result, why?
- git - 在这种情况下有哪些 git 命令可以帮助我?
- c# - UWP 商店 0x800701C5
- javascript - 未捕获的类型错误:无法在 JavaScript webshare api 中读取 null 的属性“addEventListener”
- android - 例外:未知编码:Android 上 kivy 上的 GBK
- java - 根据文档,Zookeeper 读取不完全一致,但创建 znode 是否完全一致?
- java - 如何使用 Android 片段将 Json 数据加载到下拉微调器中
- android - 一旦数据来自缓存,就无法再次从网络获取数据
- javascript - 如何在ui-grid angularjs中导出选定的列?