当前位置:网站首页>路由的懒加载与接口的封装
路由的懒加载与接口的封装
2022-08-09 14:54:00 【小羊卷】
路由懒加载
留备以后万一忘了
两种路由的写法
一种
import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
const routes = [
{
path: '/login',
name: 'login',
component: () => import('@/views/login')
},
{
path: '/',
// name: 'layout', // 如果父路由有默认子路由,那它的 name 没有意义
component: () => import('@/views/layout'),
children: [
{
// 默认子路由,只能有1个
path: '',
name: 'home',
component: () => import('@/views/home')
},
{
path: '/qa',
name: 'qa',
component: () => import('@/views/qa')
},
{
path: '/video',
name: 'video',
component: () => import('@/views/video')
},
{
path: '/my',
name: 'my',
component: () => import('@/views/my')
}
]
},
{
path: '/search',
name: 'search',
component: () => import('@/views/search')
},
{
path: '/article/:articleId',
name: 'article',
component: () => import('@/views/article'),
// 开启 Props 传参,说白了就是把路由参数映射到组件的 props 数据中
props: true
},
{
path: '/user/profile',
name: 'user-profile',
component: () => import('@/views/user-profile')
}
];
const router = new VueRouter({
routes
});
export default router;第二种
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
{
path: '/login',
component: () => import('@/views/login/index'),
hidden: true,
},
{
path: '/404',
component: () => import('@/views/404'),
hidden: true,
},
// 主页
{
path: '/',
component: Layout,
redirect: '/dashboard',
children: [
{
path: 'dashboard',
name: 'Dashboard',
component: () => import('@/views/dashboard/index'),
meta: { title: '主页', icon: 'dashboard' },
},
],
},
// 审批 approvals
{
path: '/',
component: Layout,
children: [
{
path: 'approvals',
name: 'Approvals',
component: () => import('@/views/approvals/index'),
meta: { title: '审批', icon: 'tree-table' },
},
],
},
// 组织架构 departments
{
path: '/',
component: Layout,
children: [
{
path: 'departments',
name: 'Departments',
component: () => import('@/views/departments/index'),
meta: { title: '组织架构', icon: 'tree' },
},
],
},
// 员工 employees
{
path: '/',
component: Layout,
children: [
{
path: 'employees',
name: 'Employees',
component: () => import('@/views/employees/index'),
meta: { title: '员工', icon: 'people' },
},
{
path: 'staffInfo/:id',
name: 'StaffInfo',
component: () => import('@/views/staffInfo/index'),
hidden: true,
},
{
path: 'hrsaas/import',
name: 'hrsaas',
component: () => import('@/views/import/index'),
hidden: true,
},
{
path: 'printer/:id',
name: 'Printer',
component: () => import('@/views/Printer/index'),
hidden: true,
},
],
},
// 权限管理 permission
{
path: '/',
component: Layout,
children: [
{
path: 'permission',
name: 'Permission',
component: () => import('@/views/permission/index'),
meta: { title: '权限管理', icon: 'lock' },
},
],
},
// 考勤 attendances
{
path: '/',
component: Layout,
children: [
{
path: 'attendances',
name: 'Attendances',
component: () => import('@/views/attendances/index'),
meta: { title: '考勤', icon: 'excel' },
},
],
},
// 工资 salarys
{
path: '/',
component: Layout,
children: [
{
path: 'salarys',
name: 'Salarys',
component: () => import('@/views/salarys/index'),
meta: { title: '工资', icon: 'money' },
},
],
},
// 公司设置 setting
{
path: '/',
component: Layout,
children: [
{
path: 'setting',
name: 'Setting',
component: () => import('@/views/setting/index'),
meta: { title: '公司设置', icon: 'setting' },
},
],
},
// 社保 social
{
path: '/',
component: Layout,
children: [
{
path: 'social',
name: 'Social',
component: () => import('@/views/social/index'),
meta: { title: '社保', icon: 'table' },
},
],
},
// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true },
]
const createRouter = () =>
new Router({
// mode: 'history', // require service support
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes,
})
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
const newRouter = createRouter()
router.matcher = newRouter.matcher // reset router
}
export default router
接口封装
import request from '@/utils/request'
/**
* 用户登录
*/
export function login(data) {
return request({
url: '/sys/login',
method: 'post',
data,
})
}边栏推荐
- C language operator precedence
- PAT1027 打印沙漏
- 突然想分析下房贷利率及利息计算
- Analysis of the common methods and scopes of the three servlet containers
- The recycle bin has been showed no problem to empty the icon
- pytorch从零搭建神经网络实现多分类(训练自己的数据集)
- 数组学习笔记
- Qt控件-QTextEdit使用记录
- WebGL:BabylonJS入门——初探:数据展示
- Seize the opportunity of quantitative trading fund products, and quantitative investment has room for development?
猜你喜欢
随机推荐
Suddenly want to analyze the mortgage interest rate and interest calculation
光线的数值追踪
Introduction to OpenCV and build the environment
How to flexibly use the advantages of the quantitative trading interface to complement each other?
Basic principles and common methods of digital image processing
How to List < Map> grouping numerical merge sort
欢迎使用CSDN-markdown编辑器
怎么才可以知道量化程序化交易是否有效?
单向链表几个比较重要的函数(包括插入、删除、反转等)
Several important functional operations of general two-way circular list
多线程学习
navicat for Oraclel链接oracle 报错oracle library is not loaded的解决办法
How to make your quantitative trading system have probabilistic advantages and positive return expectations?
抢占量化交易基金产品先机,量化投资有发展空间?
常微分方程的幂级数解法
Use tensorboard remotely on the server
What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.
排序方法(希尔、快速、堆)
编译器不同,模式不同,对结果的影响
浅谈一下量化交易与程序化交易









