Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sunw730 opened this issue Jan 15, 2018 · 0 comments
Open

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

Sunw730 opened this issue Jan 15, 2018 · 0 comments

Comments

@Sunw730
Copy link

Sunw730 commented Jan 15, 2018

在页面通过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项目的时候不利于使用模板技术生成布局页面了吧?

@Sunw730 Sunw730 changed the title bug? 调用require函数时 data-main指定的文件尚未加载完成. Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant