zoukankan      html  css  js  c++  java
  • requirejs的使用

    requirejs的使用

    加载网络模块

    使用CDN

    requirejs.config({
        "baseUrl": "js/lib",
        "paths": {
          "app": "../app",
          "jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min"
        }
    });
    

    shim配置

    https://github.com/requirejs/example-jquery-shim

    requirejs.config({
        "baseUrl": "js/lib",
        "paths": {
          "app": "../app"
        },
        "shim": {
            "jquery.alpha": ["jquery"],
            "jquery.beta": ["jquery"]
        }
    });
    

    // Load the main app module to start the app
    requirejs(["app/main"]);
    App/main.js is where the app logic is:

    define(["jquery", "jquery.alpha", "jquery.beta"], function($) {
        //the jquery.alpha.js and jquery.beta.js plugins have been loaded.
        $(function() {
            $('body').alpha().beta();
        });
    });
    ``
    
    ####加载非AMD规范模块
    
    定义依赖和导出对象
    
    ```javascript
      require.config({
        shim: {
    
          'underscore':{
            exports: '_'
          },
          'backbone': {
            deps: ['underscore', 'jquery'],
            exports: 'Backbone'
          }
        }
      });
    

    requirejs插件

    http://www.ruanyifeng.com/blog/2012/11/require_js.html

    domready插件,可以让回调函数在页面DOM结构加载完成后再运行。

     require(['domready!'], function (doc){
        // called once the DOM is ready
      });
    

    text和image插件,则是允许require.js加载文本和图片文件。

    define([
        'text!review.txt',
        'image!cat.jpg'
        ],
    
        function(review,cat){
          console.log(review);
          document.body.appendChild(cat);
        }
      );
    

    类似的插件还有json和mdown,用于加载json文件和markdown文件。

  • 相关阅读:
    ViewState与Session [转]
    HTML5和HTML4的主要区别 [转]
    委托 与 Lambda
    ArcGIS 基础4-删除数据
    ArcGIS 基础3-新建数据
    ArcGIS 基础2-编辑数据
    ArcGIS 基础1-打开地图文档并浏览
    成都地铁线路图
    矢量数据库合并工具
    ArcGIS Pro试用下载步骤
  • 原文地址:https://www.cnblogs.com/wancy86/p/requirejs.html
Copyright © 2011-2022 走看看