zoukankan      html  css  js  c++  java
  • RequireJs学习笔记之data-main Entry Point

    You will typically use a data-main script to set configuration options and then load the first application module. Note: the script tag require.js generates for your data-main module includes the async attribute. This means that you cannot assume that the load and execution of your data-main script will finish prior to other scripts referenced later in the same page.

    翻译:通常会使用data-main设置的脚本里写一些配置选项,然后读取你配置里的第一个程序模块,注意require.js生成的data-main模块里的配置包含异步属性,注意你无法确定在同一个页面里面,你的data-main设置的脚本会在你其他脚本之前运行完,其他就是只的在文件位置上data-main后面的脚本

    script data-main="scripts/main" src="scripts/require.js"></script>
    <script src="scripts/other.js"></script>---》这个就是其他所指的文件

    For example, this arrangement will fail randomly when the require.config path for the 'foo' module has not been set prior to it being require()'d later:

    例如这个写法就会很容易造成问题,require.config配置的这个path属性没有在require()执行前设置,而是是在他执行后设置

    <script data-main="scripts/main" src="scripts/require.js"></script>--》标签1
    <script src="scripts/other.js"></script>--》标签2
    
    // contents of main.js:
    require.config({
        paths: {
            foo: 'libs/foo-1.1.3'
        }
    });
    
    // contents of other.js:
    
    // This code might be called before the require.config() in main.js-》
    // has executed. When that happens, require.js will attempt to-》
    // load 'scripts/foo.js' instead of 'scripts/libs/foo-1.1.3.js'
    //翻译:下面的代码或许在require.config()执行之前就被调用了,
    //会造成require.js会加载script目录下的foo.js。而不是scripts/libs下的foo-1.1.3,
    //在不设置baseUrl情况下requirejs会默认加载引用了requirejs文件所在的目录里的模块-》src="scripts/require.js"的
    //总结就是说 不要以为标签2在标签1下面。标签1里的东西就会执行完
    require( ['foo'], function( foo ) { });


  • 相关阅读:
    static&初始化顺序
    java基础语法
    MySQL调优
    Nnginx调优
    cisco 一些基本命令
    路由器密码忘记
    利用GetPrivateProfileString读取配置文件(.ini)
    MFC中OnActivate函数解析
    在MFC应用程序中传输的消息类型
    MFC中UpdateData函数解析
  • 原文地址:https://www.cnblogs.com/or2-/p/3404871.html
Copyright © 2011-2022 走看看