解决require()未声明问题(require.js实例,小白)

2021/8/18 23:11:45

本文主要是介绍解决require()未声明问题(require.js实例,小白),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

目录结构:

代码:

Test_graph.html:

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 </head>
 7 <body>
 8 <script src='../../js/jquery-3.3.1.min.js'></script>
 9 <script src="./REQUIRE/lib/require.js" data-main="./REQUIRE/app"></script>
10 <script src='REQUIRE/app/ngraph.graph.min.js'></script>
11 </body>
12 </html>
Test_graph

REQUIRE/app.js

 1 // For any third party dependencies, like jQuery, place them in the lib folder.
 2 
 3 // Configure loading modules from the lib directory,
 4 // except for 'app' ones, which are in a sibling
 5 // directory.
 6 requirejs.config({
 7     baseUrl: './REQUIRE/lib',
 8     paths: {
 9         app: '../app'
10     }
11 });
12 
13 // Start loading the main app file. Put all of
14 // your application logic in there.
15 requirejs(['./app/main']);
app.js

REQUIRE/lib/require.js:https://requirejs.org/docs/release/2.3.6/comments/require.js

REQUIRE/app/ngraph.graph.min.js:https://unpkg.com/ngraph.graph@19.0.0/dist/ngraph.graph.min.js

REQUIRE/app/main.js

 1 define(function (require) {
 2     // Load any app-specific modules
 3     // with a relative require call,
 4     // like:
 5     alert("**1*");
 6     var createGraph = require('./ngraph.graph.min');
 7     alert("**2*");
 8     var g = createGraph();
 9     g.addNode('hello');
10     g.addNode('world', 'custom data');
11     g.addLink('hello', 'world');
12     g.addNode('server', {
13         status: 'on',
14         ip: '127.0.0.1'
15     });
16     var world=g.getNode("world");
17     alert(JSON.stringify(world));
18 
19 });

 



这篇关于解决require()未声明问题(require.js实例,小白)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程