欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 家装 > vue3(笔记)4.0 vueRouter.导航守卫.ElementPuls知识点

vue3(笔记)4.0 vueRouter.导航守卫.ElementPuls知识点

2025/5/12 20:23:06 来源:https://blog.csdn.net/2302_77002233/article/details/145990123  浏览:    关键词:vue3(笔记)4.0 vueRouter.导航守卫.ElementPuls知识点

---vueRouter

创建路由:

完整写法(懒加载):

默认写法与vue2一致:  导入 然后 写成component: LoginPage

import { createRouter, createWebHistory } from 'vue-router'const router = createRouter({history: createWebHistory(import.meta.env.BASE_URL), routes: [{path:'/login', component: () =>import('@/views/login/LoginPage.vue')},// 设置默认路径{path:'/',component: () =>import('@/views/layout/LayoutContainer.vue'),redirect:'/article/manage',children:[{path:'/article/manage', component: () =>import('@/views/article/ArticleManage.vue')},{path:'/article/channel', component: () =>import('@/views/article/ArticleChannel.vue')}]}]
})

路由对象以及路由参数: 

                                                       跳转: router.push('/') 

---vueRouter导航守卫

文档:

示例代码:

 登录访问拦截,和vue2相比 没有了next() 默认放行 return true

router.beforeEach((to)=>{const userStore = useUserStore()
//  判断是否有token值 并且 进入的不是非登录页   if(!userStore.token && to.path!=='/login') return '/login'
})

--- ElementPlus 安装

全局中文显示(APP.js文件):

<script setup>
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
</script><template>
<div><el-config-provider :locale="zhCn"><router-view></router-view> </el-config-provider>
</div>
</template><style scoped></style>

              ElementPlus支持使用自定义插槽来添加修改数据(详细可查看官网)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词