zoukankan      html  css  js  c++  java
  • vuerouter路由懒加载

     

    正常配置

    import Vue from 'vue'
    import Router from 'vue-router'
    import Login from '@/components/pages/login'
    import Capture from '@/components/pages/capture'
    import List from '@/components/pages/list'
    import CaptureFail from '@/components/pages/capture-fail'
    
    Vue.use(Router)
    
    export default new Router({
      routes: [
        {
          path: '/',
          name: 'Login',
          component: Login
        },
        {
          path: '/capture',
          name: 'Capture',
          component: Capture
        },
        {
          path: '/list',
          name: 'List',
          component: List
        },
        {
          path: '/capture-fail',
          name: 'CaptureFail',
          component: CaptureFail
        }
      ]
    })
    

    懒加载配置

    import Vue from 'vue'
    import Router from 'vue-router'
    // import Login from '@/components/pages/login'
    // import Capture from '@/components/pages/capture'
    // import List from '@/components/pages/list'
    // import CaptureFail from '@/components/pages/capture-fail'
    
    Vue.use(Router)
    
    export default new Router({
      routes: [
        {
          path: '/',
          name: 'Login',
          component: resolve => require(['@/components/pages/login'], resolve) // Login
        },
        {
          path: '/capture',
          name: 'Capture',
          component: resolve => require(['@/components/pages/capture'], resolve) // Capture
        },
        {
          path: '/list',
          name: 'List',
          component: resolve => require(['@/components/pages/list'], resolve) // List
        },
        {
          path: '/capture-fail',
          name: 'CaptureFail',
          component: resolve => require(['@/components/pages/capture-fail'], resolve) // CaptureFail
        }
      ]
    })
    
    

    说明

    npm run build后会新增路由数量相匹配的.js文件,在切到相应路由时动态加载这个文件。

    参考

    懒加载 · vue-router

    vue-router路由懒加载(解决vue项目首次加载慢)

    GitHub:mazeyqian
    Blog:blog.mazey.net
  • 相关阅读:
    TP5.x——打印SQL语句
    PHP——运行shell命令|脚本
    Git——取消merge状态
    Typecho——简介及安装
    Vue——服务器上部署vue.js
    Node——服务器上安装Node.js
    PHP——敏感词过滤
    PHP——emjoin表情存入数据库
    什么是脚本语言
    全局拦截各种http请求
  • 原文地址:https://www.cnblogs.com/onesea/p/15577178.html
Copyright © 2011-2022 走看看