zoukankan      html  css  js  c++  java
  • 解决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 });
  • 相关阅读:
    python数据1-5
    python密码1-2
    css Loading 教程
    定制化jQuery
    PHP 将MySQL数据导出csv
    windows MySQL 5.7 导出表方法记录
    前端UI
    我的框架说明文档 2016-04-06
    微信公众号内支付(三)
    微信公众号内支付(二)
  • 原文地址:https://www.cnblogs.com/smartisn/p/15159023.html
Copyright © 2011-2022 走看看