javascript - Issues with require.js introducing js
滿天的星座
滿天的星座 2017-06-12 09:27:31
0
4
648



##1: require.js cannot request page.js

2: Can require.js only request js files defined with define? If there are no files defined with define, can it not be obtained?

3: How can I use require.js to get the page.js file?

滿天的星座
滿天的星座

reply all(4)
Peter_Zhu

1: What do you mean by not being able to request? console.log(Page)No output?

Open the network tab in the developer tools and you should be able to see the request for page.js

2: It can be obtained and run, but the Page variable in the callback function is undefined because you did not define it in Page.js

3:

黄舟

First check whether there is any error in the console; then check whether the written js complies with AMD/CMD specifications.
Of course it is best to define define()

黄舟

Quoting Ruan Yifeng’s tutorial: http://www.ruanyifeng.com/blo...
require.js has several important APIs.
define defines the module, the default file name is the name of the module.
require Just write the name of the module in the array without the suffix (.js).
Configure the reference path for module introduction, then define the module, and then introduce the module.

巴扎黑
  1. It is normal that the request cannot be received. Your page.js does not write the AMD loading header, and require.js does not recognize it at all.

  2. If there is an AMD header, load it normally. If there is no AMD header, use require.config to configure the shim.

  3. Add an AMD header to page.js or directly add a UMD header (that is, it can be loaded with AMD/CMD at the same time, and can be seen in many modules on github).

  4. Please refer directly to Ruan Yifeng’s RequireJS and AMD specifications for the documentation.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!