require.js JQ

來源:互聯網
上載者:User

標籤:let   .config   基本   define   export   data-   塊代碼   path   json   

require.js和sea.js的作用都是一樣的。

為瞭解決兩大問題,第一實現js檔案的非同步載入,避免網頁失去響應,第二管理模組之間的依賴性。

基本的模板

define(function(require,exports,module){    exports.getStyle = function (obj,name){        //你初始的模組    }})
define(function(require,exports,module){    var get = require(‘get‘);//引入初始模組(基於這塊代碼,你才可以繼續寫後面的代碼)        exports.move = function move(obj,json,complete){    //後續代碼    }})
require([‘move‘],function(mod){    mod.slide()  //後續模組的方法})

並通過

<script src="require.js" data-main=‘init‘></script>//data-main 是一個方法 後面是你最終檔案的名字。

插入到你的HTML中

jQuery也是如此,存在著依賴的關係

requires.config({    paths:{  //引入你所依賴的模組        ‘jquery‘:‘lib/jquery‘ //你的jquery存放位置,注意不能加尾碼名 .js    }});requires([‘jquery‘],    //方法輸出的jq代碼function ($){    $(‘#test‘).html(‘test‘);});

也是通過

<script src="require.js" data-main=‘init‘></script>//data-main 是一個方法 後面是你最終檔案的名字。

插入你的html

require.js JQ

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.