5 分鐘上手 Sea.js

來源:互聯網
上載者:User

標籤:style   color   io   os   使用   java   ar   檔案   sp   

為什麼使用 Sea.js ?

Sea.js 簡單、自然的代碼書寫和組織方式

相容性好

技術比較成熟,運用比較普遍。

目錄結構:

examples/  |-- sea-modules      存放 seajs、jquery 等檔案,這也是模組的部署目錄  |-- static           存放各個項目的 js、css 檔案  |     |-- hello  |     |-- lucky  |     `-- todo  `-- app              存放 html 等檔案        |-- hello.html        |-- lucky.html        `-- todo.html

在頁面中記載模組:

在 hello.html 頁尾,通過 script 引入 sea.js 後,有一段配置代碼:

// seajs 的簡單配置  seajs.config({  base: "../sea-modules/",  alias: {    "jquery": "jquery/jquery/1.10.1/jquery.js"  }})  // 載入入口模組  seajs.use("../static/hello/src/main")

sea.js 在下載完成後,會自動載入入口模組。

代碼模組:

這個小遊戲有兩個模組 spinning.js 和 main.js,遵循統一的寫法:

// 所有模組都通過 define 來定義define(function(require, exports, module) {  // 通過 require 引入依賴  var $ = require(‘jquery‘);  var Spinning = require(‘./spinning‘);  // 通過 exports 對外提供介面  exports.doSomething = ...  // 或者通過 module.exports 提供整個介面  module.exports = ...  });

上面就是 Sea.js 推薦的 CMD 模組書寫格式。



5 分鐘上手 Sea.js

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.