Comments (5)
const home = r => require.ensure([], () => r(require('../page/home/home')), 'home')
r是home方法的一个参数,同时本身也是一个方法。也就是说home方法参数必须是一个方法,如果是个普通变量则会报错。
require.ensure的第二个参数,作为home方法的callbackfun,它的返回值r(require('../page/home/home'))也就是最终的返回值。require('url')返回一个Promise()的对象,这个对象作为r方法的参数。所以r方法要想有意义,就要在方法内部使用Promise()对象的resolre或者reject.
function r(promise){
let resolve=promise.istypeof(Promise)?promise.resolve:'';
return new Promise((resolve,reject)=>{
/../
})
};
home(r);
我理解是这样
from vue2-elm.
这个webpack按需加载的配置,我直接复制官网的
from vue2-elm.
大兄弟,你理解r代表什么了吗?求解释。
我还原成ES5是这样的
const header = function (r){
require.ensure([],function (){
r(require('@/components/header/header'),header);
})
}
打印出的r是一个函数
ƒ () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
if (called) { return }
called = true;
return fn.apply(this, args)
}
关于r代表什么,已经理解清楚,现在更新一下,方便其他人理解,谢谢楼下兄弟的来信。
r = resolve ;
正确的写法是:resolve => require([URL], resolve);
这是vue懒加载的一种写法,这是一个博主的见解。https://blog.csdn.net/qq_30227429/article/details/75246433
小弟不才,最近在把自己经常用的轮子打包成一个框架,有兴趣的可以支持一下,谢谢各位。
https://github.com/zpChiu/dorea.git
from vue2-elm.
from vue2-elm.
from vue2-elm.
Related Issues (20)
- 项目演示定位报错
- 项目install不了 想问问大家是什么情况 HOT 9
- error
- 访问时500 json出现问题
- 接口获取不了 HOT 1
- 大佬页面请求500是接口出问题了吗,还是服务器崩了,项目启动不了了,救救孩子吧
- 城市接口还是用不了啊
- 大佬,结算功能进不去了,怎么回事啊
- 为什么在chrome调试的时候,源码不在src目录下?
- 首页访问接口报错504 HOT 2
- 接口崩溃
- 移动端与网页端?以及接口崩溃
- 登录注册携带了cookies还是会返回登录失败 HOT 4
- 搜索餐馆的接口用不了了 HOT 3
- 地址搜索接口用不了 HOT 2
- 基于作者的后台系统代码用vue3做了一个antd风格的管理页面
- 安装依赖总是失败 安装最新的也是一样......启动之后也是一样的sass问题 HOT 4
- 出现404问题 HOT 2
- 搜索接口不能用了吗?返回获取信息失败
- 避坑,vue2-elm这个项目根本启动不起来,install失败,启动失败,后端接口全面404 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue2-elm.