路由的懒加载与接口的封装

路由懒加载

留备以后万一忘了

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,
  })
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值