亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue+jsplumb實(shí)現(xiàn)連線繪圖

 更新時(shí)間:2022年03月29日 16:43:30   作者:qq_37656005  
這篇文章主要為大家詳細(xì)介紹了vue+jsplumb實(shí)現(xiàn)連線繪圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

vue+jsplumb實(shí)現(xiàn)連線繪圖,供大家參考,具體內(nèi)容如下

jsPlumb是一個(gè)比較強(qiáng)大的繪圖組件,它提供了一種方法,主要用于連接網(wǎng)頁上的元素。在現(xiàn)代瀏覽器中,它使用SVG或者Canvas技術(shù),而對(duì)于IE8以下(含IE8)的瀏覽器,則使用VML技術(shù)。

效果圖

1.安裝

npm install jsplumb --save

2.main.js 引入

import jsPlumb from 'jsplumb'
Vue.prototype.$jsPlumb = jsPlumb.jsPlumb

3.示例代碼

<template>
? <div>
? ? <div id="container">
? ? ? <div class="left">
? ? ? ? <ul>
? ? ? ? ? <li v-for="(item,index) in leftList" :key="'left' + index" :id="item.nodeId" name="source">
? ? ? ? ? ? {{item.name}}
? ? ? ? ? </li>
? ? ? ? </ul>
? ? ? </div>

? ? ? <div class="right">
? ? ? ? <ul>
? ? ? ? ? <li v-for="(item,index) in rightList" :key="'right' + index" :id="item.nodeId" name="target">
? ? ? ? ? ? {{item.name}}
? ? ? ? ? </li>
? ? ? ? </ul>
? ? ? </div>
? ? </div>
? </div>
</template>

<script>
? export default {
? ? name: "linkElementModal",
? ? data() {
? ? ? return {
? ? ? ? jsPlumb: null, // 緩存實(shí)例化的jsplumb對(duì)象
? ? ? ? leftList:[
? ? ? ? ? {name: 'xxx_left_1', nodeId: 'left_1'},
? ? ? ? ? {name: 'xxx_left_2', nodeId: 'left_2'},
? ? ? ? ? {name: 'xxx_left_3', nodeId: 'left_3'},
? ? ? ? ? {name: 'xxx_left_4', nodeId: 'left_4'}
? ? ? ? ],
? ? ? ? rightList:[
? ? ? ? ? {name: 'xxx_right_1', nodeId: 'right_1'},
? ? ? ? ? {name: 'xxx_right_2', nodeId: 'right_2'},
? ? ? ? ? {name: 'xxx_right_3', nodeId: 'right_3'},
? ? ? ? ? {name: 'xxx_right_4', nodeId: 'right_4'}
? ? ? ? ]
? ? ? }
? ? },
? ? mounted(){
? ? ? this.showPlumb();
? ? },
? ? methods:{
? ? ? showPlumb() {
? ? ? ? this.jsPlumb = this.$jsPlumb.getInstance({
? ? ? ? ? Container: 'container', // 選擇器id
? ? ? ? ? EndpointStyle: {radius: 0.11, fill: '#999'}, // 端點(diǎn)樣式
? ? ? ? ? PaintStyle: {stroke: '#999', strokeWidth: 2}, // 繪畫樣式,默認(rèn)8px線寬 ?#456
? ? ? ? ? HoverPaintStyle: {stroke: '#994B0A', strokeWidth: 3 }, // 默認(rèn)懸停樣式 ?默認(rèn)為null
? ? ? ? ? ConnectionOverlays: [ // 此處可以設(shè)置所有箭頭的樣式
? ? ? ? ? ? ['Arrow', { // 設(shè)置參數(shù)可以參考中文文檔
? ? ? ? ? ? ? location: 1,
? ? ? ? ? ? ? length: 12,
? ? ? ? ? ? ? paintStyle: {
? ? ? ? ? ? ? ? stroke: '#999',
? ? ? ? ? ? ? ? fill: '#999'
? ? ? ? ? ? ? }
? ? ? ? ? ? }]
? ? ? ? ? ],
? ? ? ? ? Connector: ['Straight'], // 要使用的默認(rèn)連接器的類型:直線,折線,曲線等
? ? ? ? ? DrapOptions: {cursor: 'crosshair', zIndex: 2000}
? ? ? ? });

? ? ? ? this.jsPlumb.batch(() => {
? ? ? ? ? for(let i = 0; i < this.leftList.length; i++){
? ? ? ? ? ? this.initLeaf(this.leftList[i].nodeId, 'source');
? ? ? ? ? }
? ? ? ? ? for(let j = 0; j < this.rightList.length; j++){
? ? ? ? ? ? this.initLeaf(this.rightList[j].nodeId , 'target')
? ? ? ? ? }
? ? ? ? })

? ? ? ? this.setjsPlumb(true,true);

? ? ? ? //點(diǎn)擊連線
? ? ? ? this.jsPlumb.bind('click', ?(conn, originalEvent) => {
? ? ? ? ?console.log(conn, originalEvent)
? ? ? ? })

? ? ? ? //連線時(shí)觸發(fā)
? ? ? ? this.jsPlumb.bind('connection', ?(conn, originalEvent) => {
? ? ? ? ? console.log(conn.sourceId)
? ? ? ? ? console.log(conn.targetId)
? ? ? ? })

? ? ? ? //右鍵觸發(fā)
? ? ? ? this.jsPlumb.bind('contextmenu', ?(conn, originalEvent) => {
? ? ? ? ? console.log(conn, originalEvent)
? ? ? ? })
? ? ? },
? ? ? // ?初始化規(guī)則使其可以連線、拖拽
? ? ? initLeaf(id, type) {
? ? ? ? const ins = this.jsPlumb;
? ? ? ? const elem = document.getElementById(id);
? ? ? ? if (type === 'source') {
? ? ? ? ? ins.makeSource(elem, {
? ? ? ? ? ? anchor: [1, 0.5, 0, 0], // 左 上 右 下
? ? ? ? ? ? allowLoopback: false, //允許回連
? ? ? ? ? ? maxConnections: -1 //最大連接數(shù)(-1表示不限制)
? ? ? ? ? })
? ? ? ? } else {
? ? ? ? ? ins.makeTarget(elem, {
? ? ? ? ? ? anchor: [0, 0.5, 0, 0],
? ? ? ? ? ? allowLoopback: false,
? ? ? ? ? ? maxConnections: -1
? ? ? ? ? })
? ? ? ? }
? ? ? },
? ? ? setjsPlumb(sourceFlag, targetFlag){
? ? ? ? const source = document.getElementsByName('source')
? ? ? ? const target = document.getElementsByName('target')

? ? ? ? this.jsPlumb.setSourceEnabled(source, sourceFlag)
? ? ? ? this.jsPlumb.setTargetEnabled(target, targetFlag)
? ? ? ? this.jsPlumb.setDraggable(source, false) // 是否支持拖拽
? ? ? ? this.jsPlumb.setDraggable(target, false) // 是否支持拖拽
? ? ? },
? ? }
? }
</script>

<style>
? #container{
? ? width: 500px;
? ? height: 500px;
? ? padding: 20px;
? ? position: relative; /*一定加上這句,否則連線位置發(fā)生錯(cuò)亂*/
? }

? .left{
? ? float: left;
? ? width: 150px;
? }
? .right{
? ? float: right;
? ? width: 150px;
? }

? .left li,.right li{
? ? width: 100%;
? ? border-radius: 4px;
? ? border: 1px solid #ccc;
? ? background: #efefef;
? ? margin-bottom: 20px;
? ? padding: 8px 5px;
? }
</style>

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 如何使用 Vuex的入門教程

    如何使用 Vuex的入門教程

    在vue中當(dāng)我們管理數(shù)據(jù)的時(shí)候比較亂,我們要用到下面的這個(gè)庫,本文主要介紹了如何使用 Vuex的入門教程,具有一定的參考價(jià)值,感興趣的可以了解一下
    2022-02-02
  • Vue生命周期與后端交互實(shí)現(xiàn)流程詳解

    Vue生命周期與后端交互實(shí)現(xiàn)流程詳解

    Vue的生命周期就是vue實(shí)例從創(chuàng)建到銷毀的全過程,也就是new Vue()開始就是vue生命周期的開始。Vue實(shí)例有?個(gè)完整的?命周期,也就是從開始創(chuàng)建、初始化數(shù)據(jù)、編譯模版、掛載Dom->渲染、更新->渲染、卸載等?系列過程,稱這是Vue的?命周期
    2022-11-11
  • vuex中store.commit和store.dispatch的區(qū)別及使用方法

    vuex中store.commit和store.dispatch的區(qū)別及使用方法

    這篇文章主要介紹了vuex中store.commit和store.dispatch的區(qū)別及使用方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • 解決element-ui el-checkbox的一些坑

    解決element-ui el-checkbox的一些坑

    這篇文章主要介紹了解決element-ui el-checkbox的一些坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue 動(dòng)態(tài)修改a標(biāo)簽的樣式的方法

    vue 動(dòng)態(tài)修改a標(biāo)簽的樣式的方法

    這篇文章主要介紹了vue 動(dòng)態(tài)修改a標(biāo)簽的樣式的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • 探索Vue.js component內(nèi)容實(shí)現(xiàn)

    探索Vue.js component內(nèi)容實(shí)現(xiàn)

    這篇文章主要和大家一起探索Vue.js component內(nèi)容實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Vue后臺(tái)管理系統(tǒng)之實(shí)現(xiàn)分頁功能示例

    Vue后臺(tái)管理系統(tǒng)之實(shí)現(xiàn)分頁功能示例

    本文主要介紹了Vue后臺(tái)管理系統(tǒng)之實(shí)現(xiàn)分頁功能,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • vue+iview如何實(shí)現(xiàn)拼音、首字母、漢字模糊搜索

    vue+iview如何實(shí)現(xiàn)拼音、首字母、漢字模糊搜索

    這篇文章主要介紹了vue+iview如何實(shí)現(xiàn)拼音、首字母、漢字模糊搜索,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • 如何在vue3中同時(shí)使用tsx與setup語法糖

    如何在vue3中同時(shí)使用tsx與setup語法糖

    這篇文章主要介紹了如何在vue3中同時(shí)使用tsx與setup語法糖,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-09-09
  • vue3使用echarts繪制折線圖的代碼示例

    vue3使用echarts繪制折線圖的代碼示例

    這篇文章主要為大家學(xué)習(xí)介紹了Vue3如何使用echarts實(shí)現(xiàn)繪制折線圖,文中有詳細(xì)的示例代碼供大家參考,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-07-07

最新評(píng)論