关键词搜索

源码搜索 ×
×

Web前端文档阅读笔记-vis.js在vue cli中的使用

发布2020-05-21浏览1216次

详情内容

程序运行截图如下:

首先要用npm导入的vis包

npm run vis

程序结构如下:

源码如下:

HelloWorld.vue

  1. <template>
  2. <div id="networkDemo" style="width:800px; height: 600px">
  3. </div>
  4. </template>
  5. <script>
  6. import {createNode} from 'JS/visTest.js'
  7. export default {
  8. name: 'HelloWorld',
  9. mounted(){
  10. this.init();
  11. },
  12. data () {
  13. return {
  14. msg: 'Welcome to Your Vue.js App'
  15. }
  16. },
  17. methods: {
  18. init(){
  19. createNode('networkDemo')
  20. }
  21. }
  22. }
  23. </script>
  24. <style scoped>
  25. </style>

visTest.js

  1. import vis from 'vis'
  2. export function createNode(idStr) {
  3. let nodes = new vis.DataSet([
  4. {id: 1, label: 'Node 1'},
  5. {id: 2, label: 'Node 2'},
  6. {id: 3, label: 'Node 3'},
  7. {id: 4, label: 'Node 4'},
  8. {id: 5, label: 'Node 5'},
  9. ]);
  10. let edges = new vis.DataSet([
  11. {from: 1, to: 3, label: 'Hello'},
  12. {from: 1, to: 2},
  13. {from: 2, to: 4},
  14. {from: 2, to: 5},
  15. {from: 3, to: 5}
  16. ])
  17. let container = document.getElementById(idStr);
  18. let data = {
  19. nodes: nodes,
  20. edges: edges
  21. };
  22. let options = {};
  23. let network = new vis.Network(container, data, options);
  24. }

 

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载