Skip to content

调用require函数时 data-main指定的文件尚未加载完成. #74

@Sunw730

Description

@Sunw730

在页面通过data-main加载main.js文件:
<script src="esl.js" data-main="main"></script>
然后在该页面使用
require(['jquery'], function() { console.log(jQuery); });
提示加载jQuery模块失败, 原因是执行require函数的时候 main.js 文件尚未加载完成, 所以没有找到jquery的配置信息, 这里是否可以优化一下呢?
以下代码可以正常运行, 但是很鸡肋:
setTimeout(function() { require(["jquery"], function() { console.log(jQuery) }) }, 500)

另外 , data-main指定的路径不能使用相对目录吗?
如果我的页面目录层级不一致, 那么data-main指定的路径也不一致, 这样开发web项目的时候不利于使用模板技术生成布局页面了吧?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions