Vue 3和Vue-Router 4中的嵌套命名子组件路由

vhipe2zx  于 2023-04-21  发布在  Vue.js
关注(0)|答案(1)|浏览(160)

我基本上是在尝试这样做:

path: '/',
name: '',
components: {
  appbar: () => import('@/components/Appbar.vue'),
  navigation: () => import('@/components/Navigation.vue'),
  default: () => import('@/views/Triple.vue')
},
children: [
  {
    path: '',
    name: 'home',
    components: {
      first: {
        component: () => import('@/views/Table.vue'),
        children: [
          {
            path: '',
            component: () => import('@/components/home/tableone.vue')
          }
        ]
      },
      second: {
        component: () => import('@/views/Table.vue'),
        children: [
          {
            path: '',
            component: () => import('@/components/home/tabletwo.vue')
          }
        ]
      },
      third: {
        component: () => import('@/views/Table.vue'),
        children: [
          {
            path: '',
            component: () => import('@/components/home/tablethree.vue')
          }
        ]
      }
    }
  },

其中:
表vue本质上只是一个<router-view></router-view>
Triple Vue本质上是三个<router-view name="first"></router-view>,分别用于在页面上呈现第一个、第二个和第三个组件。
我正在尝试使用Vue Router 4构建我的UI,以尽可能多地重用组件。
有没有一种方法可以使用命名视图为子级提供完整的定义,或者有没有更好的方法?

xuo3flqw

xuo3flqw1#

一种可行的方法是:

path: '/',
name: '',
components: {
  appbar: () => import('@/components/Appbar.vue'),
  navigation: () => import('@/components/Navigation.vue'),
  default: () => import('@/views/TripleView.vue')
},
children: [
  {
    path: '',
    name: 'home',
    props: { 
      first: { component: 'Incoming', title: 'Incoming Calls'}, 
      second: { component: 'FollowUp', title: 'Follow Up Calls' }, 
      third: { component: 'Agent', title: 'Active Agents' },
    },
    components: {
      first: () => import('@/views/Table.vue'),
      second: () => import('@/views/Table.vue'),
      third: () => import('@/views/Table.vue')
    },
    children: [
      {
        path: '',
        components: 
        {
          Incoming: () => import('@/components/home/IncomingCallTable.vue'),
          FollowUp: () => import('@/components/home/FollowUpTable.vue'),
          Agent: () => import('@/components/home/AgentsTable.vue')
        }
      }
    ]
  },

让表通过prop接受一个名称,并将其用于路由器命名的视图。
但是当您从另一个页面路由回主页时,它不起作用,只有初始加载起作用。

相关问题