Vue3 流程图组件库 Vue Flow 简单使用
2024-10-22 05:12:41
官网
安装
npm i --save @vue-flow/core
yarn add @vue-flow/core
pnpm i @vue-flow/core
使用
<template>
<VueFlow v-model="elements" />
</template>
<script setup>
import { VueFlow } from '@vue-flow/core'
const elements = ref([
// Nodes
// An input node, specified by using `type: 'input'`
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
// Default nodes, you can omit `type: 'default'`
{ id: '2', label: 'Node 2', position: { x: 100, y: 100 }, },
{ id: '3', label: 'Node 3', position: { x: 400, y: 100 } },
// An output node, specified by using `type: 'output'`
{ id: '4', type: 'output', label: 'Node 4', position: { x: 400, y: 200 } },
// Edges
// Most basic edge, only consists of an id, source-id and target-id
{ id: 'e1-3', source: '1', target: '3' },
// An animated edge
{ id: 'e1-2', source: '1', target: '2', animated: true },
])
</script>
<style>
/* these are necessary styles for vue flow */
@import "@vue-flow/core/dist/style.css";
/* this contains the default theme, these are optional styles */
@import "@vue-flow/core/dist/theme-default.css";
</style>
常用功能:
- 画布居中
import { VueFlow, useVueFlow } from "@vue-flow/core";
const { onPaneReady } = useVueFlow();
const state = reactive({
instance: null,
});
onPaneReady((instance) => {
instance.fitView();
// 将对象缓存
state.instance = instance;
});
// 设置缩放级别
state.instance.fitView({ offset: { y: 50 } });
state.instance.zoomTo(1);
- 点击事件
<VueFlow
v-model="flowElement"
:style="{ background: 'transparent' }"
:default-zoom="1"
fit-view-on-init
@nodeClick="nodeClickHandler"
/>
const nodeClickHandler = (props) => {
const node = props.node;
console.log(node.id);
};
最新文章
- 关于SSH的一些tricks
- 修改mysql默认字符编码出现的Job failed to start解决方法
- jsp页面路径问题
- js-方法
- shell join 参数详细说明
- 5个有用的.net profiling工具(转)
- 脚本学习python和linux-shell和jQuery(javascript)
- Java容器详解
- OLE-DB 操作excel 基本
- C++ 类的继承、虚拟继承、隐藏、占用空间
- mysql编码设置 [http://blog.knowsky.com/254652.htm]
- 从零开始学习springboot之springboot搭建
- 关于PHP新手学习的一些指导与建议,新手快到我碗里来!
- Qt 信号如何自动连接槽函数?
- js监听事件
- Linux启动顺序、运行级别及开机启动
- css 实现背景图片不跟着滚动条滚动而滚动
- nat123学习笔记
- MySQL之开启远程连接
- 浅析PCIe链路LTSSM状态机