Git Product home page Git Product logo

Comments (5)

 avatar commented on July 3, 2024 1

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.

bailicangdu avatar bailicangdu commented on July 3, 2024

这个webpack按需加载的配置,我直接复制官网的

from vue2-elm.

zpChiu avatar zpChiu commented on July 3, 2024

大兄弟,你理解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.

RemindAutumn avatar RemindAutumn commented on July 3, 2024

from vue2-elm.

zpChiu avatar zpChiu commented on July 3, 2024

from vue2-elm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.