component: resolve => require(['../pages/home.vue'], resolve)

vue 路由的懒加载

import Vue from 'vue'
import VueRouter from 'vue-router'
// "@"相当于".."
import Detail from '../pages/goodsDetail'
import Msg from '../components/message.vue'
// 使用路由
Vue.use(VueRouter)
export default new VueRouter({
mode: 'history',
routes: [
{
// 进行路由配置,规定'/'引入到home组件
path: '/',
component: resolve => require(['../pages/home.vue'], resolve),
meta: {
title: 'home'
}
},
{
path: '/msg',
component: Msg
},
{
path: '/detail',
component: Detail,
children: [
{
path: 'msg',
component: Msg
}
]
}
]
})
component: resolve => require(['../pages/home.vue'], resolve),

如果用import引入的话,当项目打包时路由里的所有component都会打包在一个js中,造成进入首页时,需要加载的内容过多,时间相对比较长。

当你用require这种方式引入的时候,会将你的component分别打包成不同的js,加载的时候也是按需加载,只用访问这个路由网址时才会加载这个js。

你可以打包的时候看看目录结构就明白了。

component: resolve => require(['../pages/home.vue'], resolve)的更多相关文章

  1. component: resolve => require(['../pages/home.vue'], resolve)-装载

    import Vue from 'vue'import VueRouter from 'vue-router'// "@"相当于".."import Detai ...

  2. component:(resolve) => require

    resolve => require(['../pages/home.vue'], resolve)这种写法是异步模块获取,打包的时候每次访问这个路由的时候会单调单个文件,按需加载,不过这种写法 ...

  3. 解决[BScroll warn]: Can not resolve the wrapper DOM. Vue better-scroll

    在开发项目过程中,使用better-scroll插件中遇到了滚动一次重复提示相同错误 [BScroll warn]: Can not resolve the wrapper DOM. Vue bett ...

  4. 如何在require中使用VUE

    现在网上抄的沸沸扬扬的VUE看来是个很NB的东西啊,看了一下,确实相对于angular1来说简化了不少东西,性能方面也比angular1要好很多,所以现在用的人越来越多了,于是作为前端,学习一下新东西 ...

  5. [Vue @Component] Define Props on a Vue Class with vue-property-decorator

    While traditional Vue components require a data function which returns an object and a method object ...

  6. [Vue @Component] Control Template Contents with Vue's Render Function

    Declaring templates and elements inside of templates works great for most scenarios. Sometimes you n ...

  7. Gitee 码云 pages 搭建vue项目记录

    首先要在.gitignore文件去掉/dist,这个文件默认是不上传的,但是执行打包bulid的时候会生成dist文件,而线上访问的是打包之后的dist文件: vue.config.js文件,如下图箭 ...

  8. error in ./src/pages/login.vue?vue&type=style&index=0&lang=less&

    vue-cli3创建less工程,npm run serve 无法运行 bug解决方法: rm -rf node-modules 修改package.json为 "less": & ...

  9. Vue加载组件、动态加载组件的几种方式

    https://cn.vuejs.org/v2/guide/components.html https://cn.vuejs.org/v2/guide/components-dynamic-async ...

随机推荐

  1. Entity Framework Tutorial Basics(5):Create Entity Data Model

    Create Entity Data Model: Here, we are going to create an Entity Data Model (EDM) for SchoolDB datab ...

  2. Python pika, TypeError: exchange_declare() got an unexpected keyword argument 'type' 问题修复

    网上很多写法都是 type='fanout' 这样的.(这里是基于python=3.6版本, pika=0.13.0 版本) credentials = pika.PlainCredentials(' ...

  3. [译]javascript中定义函数的各种方法

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...

  4. Bugly升级应用集成指南

    1.配置 app/build.gradle android { defaultConfig { ndk { //设置支持的SO库架构 abiFilters 'armeabi' //, 'x86', ' ...

  5. angular 导出excel

    http://www.cnblogs.com/gzhlt/p/5274702.html 引用 2 楼 u012129566 的回复: Quote: 引用 1 楼 loveshrimp423 的回复: ...

  6. springboot结合swagger生成接口文档

    原文链接:https://www.cnblogs.com/xu-lei/p/7423883.html https://www.jianshu.com/p/b9ae3136b292 前后台分离的开发渐渐 ...

  7. iOS自定义相机

    1.首先声明以下对象 #import <AVFoundation/AVFoundation.h> //捕获设备,通常是前置摄像头,后置摄像头,麦克风(音频输入) @property (no ...

  8. P3941 入阵曲

    \(\color{#0066ff}{ 题目描述 }\) 小 F 很喜欢数学,但是到了高中以后数学总是考不好. 有一天,他在数学课上发起了呆:他想起了过去的一年.一年前,当他初识算法竞赛的 时候,觉得整 ...

  9. 给花_Q

  10. php 生成读取csv文件并解决中文乱码

    csv其实是文本文件,但是里面的内容是利用逗号分隔的. 1. 生成csv文件 function new_csv($arr) { $string=""; foreach ($arr ...