Requirejs Simple Application

Source: Internet
Author: User

1, first import the corresponding JS file

    <script src= "Js/require.js" ></script>    <script src= "Js/mian.js" ></script>    < Script src= "Js/index.js" ></script>
Require.js is Requirejs library, Mian.js is used to write require configuration information, and index is to write their own logic code
2. Write Mian.js configuration information
require.config ({    baseUrl:' js/',// definition with path     paths:{        ' jquery ': ' jquery ',        ' bootstrap ': ' Bootstrap.min ',        ' utils ': ' Utils '    },       dependency, load boostrap before loading jquery        shim:{' Bootstrap ': {            ' deps ': [' jquery ']}}}    );

3. Then implement your own code in your Index.js file

// Simple introduction of jquery library    function ($) {        $ ("Body"). css ({            "background-color": "Red"        })     ;

Introducing JS libraries through dependency relationships

// dependencies in Mian.js, load boostrap before loading jquery     shim:{        ' Bootstrap ': {            ' deps ': [' jquery ']        }    }//  the jquery library function () is then introduced in its own index.js// dependencies when introducing the Boostrap library    () {        $ ("Body"). css ({            "background-color": "Red"        })     ;

4. Define your own Utils.js library

define ([' jquery '],function($) {    return  {change        :function () {            $ ("Body"). css ({                "background-color": "Red"            });        },        show: function () {            alert ("show");}}        );

In your own JS file


Customize your own library, and then introduce
Require ([' utils '], function (utils) {
Utils.show ();
Utils.change ();
});

Resources: http://download.csdn.net/detail/u013865056/9915553

Requirejs Simple Application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.