这里主要是针对vis的network图进行节点动态添加

图用的是vis.js,表单使用的是element-ui

程序运行截图如下:

添加一个节点:

这里是不需要刷新页面就能添加的。

程序结构如下:

关键源码如下:

FormGroup.vue

<template><el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm"><el-form-item label="id" prop="pass"><el-input v-model="ruleForm.pass" autocomplete="off"></el-input></el-form-item><el-form-item label="结点名" prop="checkPass"><el-input v-model="ruleForm.checkPass" autocomplete="off"></el-input></el-form-item><el-form-item label="连接到节点ID" prop="age"><el-input v-model.number="ruleForm.age"></el-input></el-form-item><el-form-item><el-button type="primary" @click="submitForm('ruleForm')">提交</el-button><el-button @click="resetForm('ruleForm')">重置</el-button></el-form-item></el-form>
</template><script>import {addNode} from 'JS/visTest.js'export default {data() {let checkAge = (rule, value, callback) => {};let validatePass = (rule, value, callback) => {};let validatePass2 = (rule, value, callback) => {};return {ruleForm: {pass: '',checkPass: '',age: ''},rules: {pass: [{ validator: validatePass, trigger: 'blur' }],checkPass: [{ validator: validatePass2, trigger: 'blur' }],age: [{ validator: checkAge, trigger: 'blur' }]}};},methods: {submitForm(formName) {addNode(this.ruleForm['pass'], this.ruleForm['checkPass'], this.ruleForm['age']);},resetForm(formName) {this.$refs[formName].resetFields();}}}
</script>

HelloWorld.vue

<template><div><div id="networkDemo" style="width:800px; height: 600px"></div><FormGroup></FormGroup></div></template><script>import {createNode} from 'JS/visTest.js'import FormGroup from './FormGroup'
export default {name: 'HelloWorld',mounted(){this.init();},components:{FormGroup},data () {return {msg: 'Welcome to Your Vue.js App'}},methods: {init(){createNode('networkDemo')}}
}
</script><style scoped>
</style>

main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'Vue.config.productionTip = falseVue.use(ElementUI)/* eslint-disable no-new */
new Vue({el: '#app',router,components: {App},template: '<App/>'
})

visTest.js

import vis from 'vis'let nodes;
let edges;export function createNode(idStr) {nodes = new vis.DataSet([{id: 1, label: 'Node 1'},{id: 2, label: 'Node 2'},{id: 3, label: 'Node 3'},{id: 4, label: 'Node 4'},{id: 5, label: 'Node 5'},]);edges = new vis.DataSet([{from: 1, to: 3, label: 'Hello'},{from: 1, to: 2},{from: 2, to: 4},{from: 2, to: 5},{from: 3, to: 5}])let container = document.getElementById(idStr);let data = {nodes: nodes,edges: edges};let options = {};let network = new vis.Network(container, data, options);
}export function addNode(id, label, toId){let newNode = {id: id, label: label};let line = {from: id, to: toId};console.log(newNode)nodes.add(newNode);edges.add(line);console.log("add Node over");
}

Web前端文档阅读笔记-vis.js动态添加节点(vue cli环境)相关推荐

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

    程序运行截图如下: 首先要用npm导入的vis包 npm run vis 程序结构如下: 源码如下: HelloWorld.vue <template><div id="n ...

  2. two.js文档阅读笔记-two.js的基本使用

    介绍 two.js是一个前端绘制2d图形的api.可以使用svg,canvas,webgl进行渲染. 基本使用 代码如下: <!DOCTYPE html> <html lang=&q ...

  3. FreeRTOS官方指导文档阅读笔记

    FreeRTOS官方指导文档阅读笔记 基于 161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf,可 ...

  4. Qt文档阅读笔记-共享库的创建与调用

    使用共享库的符号 这个符号可以作用在变量.类.函数中,并且这些都可以被调用端使用. 在编译共享库中,需要使用export符号.在使用端调用的时候使用import符号. 这里是本人从文档中记录的笔记,大 ...

  5. Qt文档阅读笔记-加载HeightMap(高度图)构造3D地形图

    Qt文档阅读笔记-加载HeightMap(高度图)构造3D地形图 QHeightMapSurfaceDataProxy:是Q3DSurface的一个基本代理类. 他是专门加载高度图. 高度图是没有X, ...

  6. Qt文档阅读笔记-Rotations Example相关

    Rotations Example文档阅读笔记 使用这种方式,对y轴和z轴进行旋转. QQuaternion yRotation = QQuaternion::fromAxisAndAngle(0.0 ...

  7. Blockly学习之文档阅读笔记

    文档阅读来源--谷歌官网介绍: https://developers.google.com/blockly/guides/overview 概述 一个用于Web.Android.iOS的可视化代码编辑 ...

  8. Leaflet文档阅读笔记-Quick Start Guide笔记

    目录 网络加载JS和CSS 初始化地图 在地图上做标记 在地图上点击事件获得坐标 个人对这篇文档的体会 网络加载JS和CSS 先要加载css,然后在加载js <link rel="st ...

  9. NiceScroll文档阅读笔记-NiceScroll(3.7.6)基本使用

    前言 官方已经给出很好的文档了.在此本人总结下,方便以后查阅: GitHub - inuyaksa/jquery.nicescroll: nicescroll plugin for jquery - ...

最新文章

  1. UpdatePanel 后台注册脚本失效
  2. 【三分+枚举】LNOI2017 d1t1 期末考试
  3. CentOS 使用 Docker 安装 Sentry
  4. 数据库-存储过程-游标-函数
  5. POJ 3461Oulipo KMP模板
  6. iview表单验证不生效问题注意点
  7. PHP常用字符串函数
  8. php 替换数字和字母,php preg_替换非字母数字字符并选择连词,然后拆分
  9. 【报告分享】 红宝书-超级案例大赏-阿里妈妈(附下载)
  10. 现代密码学常用符号总结
  11. 安捷伦电源6319D实现GPIB通信
  12. Python的学习笔记案例4--52周存钱挑战4.0
  13. 246 中心对称数
  14. java pow_Java pow()方法
  15. 百度ai 性别_是的,ai可能是种族主义者和性别歧视者,所以我们该怎么办
  16. matplotlib绘制图表
  17. 三硝基溴硼亚酞菁(BTNSubPc)齐岳生物介绍酞菁溶解度,定制多种酞菁材料
  18. 计算机五笔字型编码方法,无字型五笔编码计算机中文输入法
  19. CoreData单表
  20. 保护眼睛的颜色#CCE8CF

热门文章

  1. 重温C++之“strcpy_s与strcpy的比较”
  2. 华为:《数字化转型,从战略到执行》报告,附102页PPT下载
  3. 堪称暴力美学的可视化大屏是怎么做的?附无代码硬核教程
  4. 如何选择高性能的数据分析工具,你需要看看数据架构的进化史!
  5. 整个csdn网站处于不死不活的状态
  6. 飞鸽传书从天齐庙南门出来
  7. 企业越来越重视即时通讯内部应用
  8. Python作为人工智能的未来,已经超越Java高居首位
  9. 对老赖 绝不要忍 !一位美女程序媛的讨薪经历...
  10. html表单php连接mysql数据库_使用HTML表单和PHP更新MySQL