注意routes的component标签

import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: '首页',
    component: ()=>import('../layout'),
    redirect: '/index',
    children:[
      {
        path:'/index',
        name: '首页',
        component:()=>import('../views/index/index')
      },
      {
        path: '/userCenter',
        name: '个人中心',
        component:()=>import('../views/userCenter/index')
      },
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Vue 3中,您可以使用Vue Router来实现标签页功能。下面是一个简单的示例: 首先,确保您已经安装了Vue Router。可以通过以下命令来安装: ``` npm install vue-router ``` 然后,创建一个名为`Tab.vue`的组件来表示标签页的内容: ```vue <template> <div> <router-link :to="`/${tab}`">{{ tab }}</router-link> <router-view></router-view> </div> </template> <script> export default { name: 'Tab', props: ['tab'] } </script> ``` 在上面的代码中,我们使用了`router-link`和`router-view`组件来实现路由导航和路由视图。 接下来,在主应用程序文件(通常是`main.js`)中,我们需要配置Vue Router并定义路由: ```javascript import { createApp } from 'vue' import { createRouter, createWebHistory } from 'vue-router' import Tab from './Tab.vue' const routes = [ { path: '/', component: Tab, props: { tab: 'Home' } }, { path: '/about', component: Tab, props: { tab: 'About' } }, // 添加更多的标签页路由 ] const router = createRouter({ history: createWebHistory(), routes }) const app = createApp({}) app.use(router) app.mount('#app') ``` 在上面的代码中,我们首先导入了`createRouter`和`createWebHistory`函数。然后,我们定义了一个包含多个标签页路由的路由配置数组。每个路由都指向了`Tab`组件,并通过`props`属性传递了标签页的名称。 最后,我们通过`createRouter`函数创建了一个路由实例,并将其与Vue应用程序关联起来。 请注意,上述代码只是一个简单示例,您可以根据自己的需求进行进一步的定制和扩展。希望对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值