前言css
愈來愈發現,前端深刻好難哦!虐成渣渣了。前端
需求:前端繪製靈活的關係圖(此demo仍是簡單的,個人需求才跨出一小步)node
安裝jquery
npm install jointjsnpm
容器,工具欄工具
<template> <div id="toolbar"> <button class="btn add-question" :click='addNode'>Add Node</button> <button class="btn add-answer">Add Answer</button> <button class="btn preview-dialog">Preview Dialog</button> <button class="btn code-snippet">Code Snippet</button> <button class="btn clear">Clear Canvas</button> <button class="btn load-example">Load Example</button> </div> <div id="myholder" @click="click_joint"></div> </template>
<script> require('../assets/css/toolbar.css') import ParamidaPay from "../paramidaPay.js" import joint from 'jointjs' import $ from 'jquery' export default { name: 'App', data: function () { return { active: true } }, mounted: function () { this.inti() }, methods: { inti(){ // 先建立joint graph 對象 var graph = new joint.dia.Graph(); //設定容器基本信息 var paper = new joint.dia.Paper({ el: document.getElementById('myholder'), width: 900, height: 700, model: graph, }); let rect = new joint.shapes.basic.Rect({ position: { x: 100, y: 30 }, size: { width: 100, height: 30 }, attrs: { rect: { fill: 'rgb(75, 74, 103)' }, text: { text: 'node', fill: 'white' } } }) let rect2 = rect.clone(); let rect3 = rect.clone(); rect2.translate(300); rect3.translate(600); let link = new joint.dia.Link({ source: { id: rect.id }, target: { id: rect2.id } }) graph.addCells([rect, rect2, rect3,link]); } }, addNode(){ } } </script> <style> #myholder{ width: 900px; height: 700px; margin: 0 auto; margin-top: 25px; border: 1px solid #d3d3d3; } </style>
運行效果ui
Fannie式總結this
是否是有點好看spa
話很少說,我實際上是爲了保存代碼,最小單元3d
而後我要接着作下去了
好了,emmmm(調研階段有更多的坑,我下一篇文章寫)