无法将第三方脚本SIGMAJS添加到我的Nuxt项目中

时间:2020-03-08 20:37:22

标签: javascript nuxt.js sigma.js

我正在尝试将脚本作为第三方添加到我的nuxt项目中。

包含每个脚本的文件夹与组成我的Web应用程序的其他文件位于同一位置。

这是我尝试添加脚本的方式:

        <template>
        <div id="container">
        </div>
    </template>

    <script src="./build/sigma.min.js"></script>
    <script>
    export default {
      head: {
        script: [
          { src: './build/sigma.min.js' },
        ]
      }
    }
    var s = new sigma(
      {
        renderer: {
          container: document.getElementById('sigma-container'),
          type: 'canvas'
        },
        settings: {
         minEdgeSize: 0.1,
         maxEdgeSize: 2,
         minNodeSize: 1,
         maxNodeSize: 8,
        }
      }
    );

    // Create a graph object
    var graph = {
      nodes: [
        { id: "n0", label: "A node", x: 0, y: 0, size: 3, color: '#008cc2' },
        { id: "n1", label: "Another node", x: 3, y: 1, size: 2, color: '#008cc2' },
        { id: "n2", label: "And a last one", x: 1, y: 3, size: 1, color: '#E57821' }
      ],
      edges: [
        { id: "e0", source: "n0", target: "n1", color: '#282c34', type:'line', size:0.5 },
        { id: "e1", source: "n1", target: "n2", color: '#282c34', type:'curve', size:1},
        { id: "e2", source: "n2", target: "n0", color: '#FF0000', type:'line', size:2}
      ]
    }

    // Load the graph in sigma
    s.graph.read(graph);
    // Ask sigma to draw it
    s.refresh();
    </script>

运行应用程序时出现此错误:

ReferenceError:未定义sigma

感谢您的帮助

0 个答案:

没有答案