Home  >  Article  >  Web Front-end  >  Require.js detailed explanation

Require.js detailed explanation

php中世界最好的语言
php中世界最好的语言Original
2018-03-14 09:15:081479browse

This time I will bring you a detailed explanation of Require.js. What are the precautions for using Require.js? The following is a practical case, let's take a look.

index.html


    
    
body //将require引入,放在html页面最下方,或设置异步请求 //即:

main.js

require.config({    //配置路径
    paths: {        "jquery": ["http://libs.baidu.com/jquery/2.0.3/jquery", "jquery.min.js"],        "a": "a"
    }
})require(["jquery", "a"], function($,a) {
    $(function() {              //调用即可,此处的a并无意义,仅为指示,与引入文件顺序有关,即若
              //function($,a)中a换了一种称谓,这里调用时保持一致即可
        a.fun1();
        alert("load finished");
    })
})

a.js

function fun1(){
   alert("it works");
 } //切记,如果需要在调用该函数,一定要记得返回,个人理解为暴露接口return {     fun1: fun1
 };
})```

I believe you have mastered the method after reading the case in this article, and there will be more exciting things. Please pay attention to other related articles on php Chinese website!

Recommended reading:

How to implement node connection to mysql

Use JS to implement sorting algorithm

The above is the detailed content of Require.js detailed explanation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How webpack packages jsNext article:How webpack packages js