1. 安装:

npm i cytoscape --save

2. 引入:main.js

import cytoscape from 'cytoscape';
Vue.prototype.$cytoscape = cytoscape;

3. demo代码:

<template>
<div id="MainCy" style="width: 100%;height: 100%;"></div>
</template>
<script>
export default {
mounted() {
var cy = this.$cytoscape({
container: document.getElementById('MainCy'), layout: {
name: 'grid',
rows: 2,
cols: 2
}, style: [{
selector: 'node',
style: {
'content': 'data(name)',
'background-color': 'magenta',
'background-image': 'url(img/shixian.png)',
}
}, {
selector: 'edge',
style: {
'content': 'data(relationship)',
'curve-style': 'bezier',
'target-arrow-shape': 'triangle',
'color': 'red',
}
}, // some style for the extension {
selector: '.eh-handle',
style: {
'background-color': 'red',
'width': 12,
'height': 12,
'shape': 'ellipse',
'overlay-opacity': 0,
'border-width': 12, // makes the handle easier to hit
'border-opacity': 0
}
}, {
selector: '.eh-hover',
style: {
'background-color': 'red'
}
}, {
selector: '.eh-source',
style: {
'border-width': 2,
'border-color': 'red'
}
}, {
selector: '.eh-target',
style: {
'border-width': 2,
'border-color': 'red'
}
}, {
selector: '.eh-preview, .eh-ghost-edge',
style: {
'background-color': 'red',
'line-color': 'red',
'target-arrow-color': 'red',
'source-arrow-color': 'red'
}
}, {
selector: '.eh-ghost-edge.eh-preview-active',
style: {
'opacity': 0
}
}
], elements: {
nodes: [{
data: {
id: 'j',
name: 'Jerry'
}
},
{
data: {
id: 'e',
name: 'Elaine'
}
},
{
data: {
id: 'k',
name: 'Kramer'
}
},
{
data: {
id: 'g',
name: 'George'
}
}
],
edges: [{
data: {
source: 'j',
target: 'e'
}
},
{
data: {
source: 'j',
target: 'k'
}
},
{
data: {
source: 'j',
target: 'g'
}
},
{
data: {
source: 'e',
target: 'j'
}
},
{
data: {
source: 'e',
target: 'k',
relationship: '1'
}
},
{
data: {
source: 'k',
target: 'j',
relationship: '2'
}
},
{
data: {
source: 'k',
target: 'e',
relationship: '3'
}
},
{
data: {
source: 'k',
target: 'g',
relationship: '4'
}
},
{
data: {
source: 'g',
target: 'j',
relationship: '5'
}
}
]
}
});
cy.nodes().on('click', (evt) => {
console.log(evt)
});
cy.edges().on('click', (evt) => {
console.log(evt)
}); },
}
</script>

demo效果:

cytoscape.js在vue项目中的安装及案例的更多相关文章

  1. d3.js在vue项目中的安装及案例

    1. 安装: npm i d3 --save 2. 引入:main.js import * as d3 from "d3"; Vue.prototype.$d3 = d3; win ...

  2. vue项目中npm安装sass,less,stylus

    用vue-cli脚手架搭建出来的,默认是用标准css的.如果你想用sass,less,stylus就需要自己手动安装一下了. 进入项目文件夹,然后安装(这里以stylus为例)stylus和stylu ...

  3. 【bcrypt】vue项目中bcrypt安装报错

    [报错] 报错时安装方法: npm install bcrypt [解决方法] npm install bcryptjs 用 bcryptjs 替换 bcrypt 即可.

  4. 在vue项目中的axios使用配置记录

    默认vue项目中已经安装axios,基于element-ui开发,主要记录配置的相关. axiosConfig.js import Vue from 'vue' import axios from ' ...

  5. 在vue项目中使用canvas-nest.js,报parameter 1 is not of type 'Element'

    canvas-nest.js是一款轻量的网页特效,如图: github地址:https://github.com/hustcc/canvas-nest.js 在普通的html项目中,只要将<sc ...

  6. vue 项目中安装npm--save-dev 和 --save 命令

    在vue项目中我们常用npm install 安装模块或插件 有两种命令把他们写入到 package.json 文件里面去 例如安装axios 安装到开发环境npm axios --save-dev ...

  7. vue 项目中实用的小技巧

    # 在Vue 项目中引入Bootstrap 有时在vue项目中会根据需求引入Bootstrap,而Bootstrap又是依赖于jQuery的,在使用npm按照时,可能会出现一系列的错误 1.安装jQu ...

  8. 如何在VUE项目中添加ESLint

    如何在VUE项目中添加ESLint 1. 首先在项目的根目录下 新建 .eslintrc.js文件,其配置规则可以如下:(自己小整理了一份),所有的代码如下: // https://eslint.or ...

  9. 浅谈 Axios 在 Vue 项目中的使用

    介绍 Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中. 特性 它主要有如下特性: 浏览器端发起XMLHttpRequests请求 Node端发起http ...

随机推荐

  1. 2018.11.24 poj3415Common Substrings(后缀数组+单调栈)

    传送门 常数实在压不下来(蒟蒻开O(3)都过不了). 但有正确性233. 首先肯定得把两个字符串接在一起. 相当于heightheightheight数组被height<kheight<k ...

  2. 2018.11.24 spoj New Distinct Substrings(后缀数组)

    传送门 双倍经验(弱化版本) 考虑求出来heightheightheight数组之后用增量法. 也就是考虑每增加一个heightheightheight对答案产生的贡献. 算出来是∑∣S∣−heigh ...

  3. vue 开发系列(一) vue 开发环境搭建

    概要 目前前端开发技术越来越像后台开发了,有一站式的解决方案. 1.JS包的依赖管理像MAVEN. 2.JS代码编译打包. 3.组件式的开发. vue 是一个前端的一站式的前端解决方案,从项目的初始化 ...

  4. Linux 安装android

    ---恢复内容开始---http://pan.baidu.com/s/1rvPP8 1.下载eclipse http://pan.baidu.com/s/1kTvNjmv http://www.cr1 ...

  5. Curry化函数

    <script> function fn(){ var i, rult = 0, len = arguments.length; for (i=0;i<len ;i++ ) { ru ...

  6. JDK线程池的使用

    转载自:https://my.oschina.net/hosee/blog/614319: 摘要: 本系列基于炼数成金课程,为了更好的学习,做了系列的记录. 本文主要介绍: 1. 线程池的基本使用 2 ...

  7. $.contains(a,b)

    jQuery.contains()函数用于判断指定元素内是否包含另一个元素. 简而言之,该函数用于判断另一个DOM元素是否是指定DOM元素的后代. 该函数属于全局jQuery对象. 语法 jQuery ...

  8. 基于VRML的虚拟校园漫游系统

    最近学习VRML的开发,在CSDN网上搜索到一个基于VRML的虚拟校园漫游系统.感觉很不错. 浏览效果如下:

  9. java基础-day30

    第07天 MySQL数据库 今日内容介绍 u 多表关系实战练习 u 多表查询 u SQL语句的练习 第1章   多表关系实战练习 1.1  多表关系--实战1--省和市 1.1.1 需求分析 在数据库 ...

  10. codeforces966 A

    这题主要就是考虑y1两侧的最近的电梯和楼梯 当时主要是考虑  如果电梯在y1和y2中间的话   那么直接做电梯就是最优解   如果在y2右边就用abs去算 然后发现其实只考虑 y1的左右两边的电梯和楼 ...