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

  • Post author:
  • Post category:其他



路由懒加载

留备以后万一忘了

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



版权声明:本文为LOxia原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。