component: resolve => require(['../pages/home.vue'], resolve)
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)的更多相关文章
- component: resolve => require(['../pages/home.vue'], resolve)-装载
import Vue from 'vue'import VueRouter from 'vue-router'// "@"相当于".."import Detai ...
- component:(resolve) => require
resolve => require(['../pages/home.vue'], resolve)这种写法是异步模块获取,打包的时候每次访问这个路由的时候会单调单个文件,按需加载,不过这种写法 ...
- 解决[BScroll warn]: Can not resolve the wrapper DOM. Vue better-scroll
在开发项目过程中,使用better-scroll插件中遇到了滚动一次重复提示相同错误 [BScroll warn]: Can not resolve the wrapper DOM. Vue bett ...
- 如何在require中使用VUE
现在网上抄的沸沸扬扬的VUE看来是个很NB的东西啊,看了一下,确实相对于angular1来说简化了不少东西,性能方面也比angular1要好很多,所以现在用的人越来越多了,于是作为前端,学习一下新东西 ...
- [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 ...
- [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 ...
- Gitee 码云 pages 搭建vue项目记录
首先要在.gitignore文件去掉/dist,这个文件默认是不上传的,但是执行打包bulid的时候会生成dist文件,而线上访问的是打包之后的dist文件: vue.config.js文件,如下图箭 ...
- 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": & ...
- Vue加载组件、动态加载组件的几种方式
https://cn.vuejs.org/v2/guide/components.html https://cn.vuejs.org/v2/guide/components-dynamic-async ...
随机推荐
- PS中图层混合模式的计算方法
https://zhuanlan.zhihu.com/p/23905865 长久以来一直用中文版本的PS,对于软件中的一些专业名字都是顾名思义,容易误入歧途,但当你真正看到英文版本的名字的时候才有豁然 ...
- 100198H Royal Federation
传送门 题目大意 国家有N个城市,任意城市可以到达任意城市,是一棵树.国王要给这些城市分省份.每个省份最少M个城市,最多3M个城市.每个省有一个首府,首府不一定是这个省的城市,只是首府到这个省各个城市 ...
- Mysql--基本配置
登录的常用参数 mysql -uroot -p 之后再加上密码 mysql -uroot -p+密码 这个方法不安全 mysql -hlocalhost -uroot -p 之后再加上密码 ...
- 使用Spring加载properties配置文件.md
背景 类似于datasource.properties之类的配置文件,最初通过Java的Properties类进行处理.这种方式有许多弊端,如每次都需要读取配置文件:若将Properties作为成员变 ...
- es6学习总结一
一.let与var 的区别 (1).作用域: let什么的变量在块级作用域内有效,而var声明则在全局作用内有效 (2).变量提升: let声明的变量不存在变量提升,即一定要在声明之后才能调用,否则就 ...
- dojo1.7 加载器
原文地址:http://dojotoolkit.org/documentation/tutorials/1.7/modules/ dojo现在支持在异步模块异步(AMD)定义中加入模块写入功能了,这使 ...
- C/C++单向链表
由于时间仓促,作者并没有进行任何的检查,总之徒手165行,调试无BUG,基本功能的实现并无大问题,可能有些细节考虑不周(这也是C/C++的诟病,小车不倒只管前推),还忘见谅. 代码是在C++环境编写, ...
- 使用canvas压缩图片 并上传
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 解决:kali linux 在vmware 虚拟机中使用bridge模式上网的问题
安装kali后,使用独立ip上网,但是设置bridge模式后依然上不了网,后来查了好多资料才解决。 能ping通网页,能ping通DNS,就是不能打开网页。 最后的原因是主机的防火墙拦截,把防火墙关了 ...
- Github加载慢,显示不完整问题解决
问题: 在访问Github网站的时候,可能会遇到网站响应超时,图片加载不出,排版错误等情况(大部分情况下是可以正常打开的). 解决方法: 修改 C:\Windows\System32\drivers\ ...