使用leader-line-vue 时垂直元素间距过小连线打转的解决

原来是这样

对应代码

复制代码
<template>
	<view>
		<button @click="changeMessage">改变消息</button>
		<!-- RenderJS 模块 -->
		<view :change:prop="renderjs.updateMessage" :prop="lineList" @touchmove="renderjs.handleTouchMove">
			<!-- 使用 ref 绑定元素 -->
			<view style="display: flex;">
				<view :ref="dataList[0].id" :id="dataList[0].id" class="node">开始节点1</view>
				<view :ref="dataList[1].id" :id="dataList[1].id" class="node">开始节点2</view>
			</view>
			<view style="margin-left: 200rpx;" :ref="dataList[2].id" :id="dataList[2].id" class="node">结束节点</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	const dataList = ref([{
			id: 'startElement',
			text: 'abc'
		},
		{
			id: 'startElementa',
			text: 'def'
		},
		{
			id: 'endElement',
			text: 'ghi'
		},
	])
	const lineList = ref([
		['startElement', 'endElement'],
		['startElementa', 'endElement']
	])

	const changeMessage = () => {
		lineList.value = JSON.parse(JSON.stringify(lineList.value))
	}
</script>
<script module="renderjs" lang="renderjs">
	import LeaderLine from 'leader-line-vue'
	export default {
		data() {
			return {
				localData: 'RenderJS 数据',
				lineOptions: {
					color: '#34C759',
					size: 3,
					path: 'grid', // 使用网格路径  // grid  fluid
					startSocket: 'bottom',
					endSocket: 'top',
					endPlug: 'arrow1',
					gradient: true,
					//startSocketGravity: [0, 1], // 向上
					//endSocketGravity: [0, -1], // 向下
					dash: {
						animation: true
					},
				},
				colorList: ['#3498db', '#E6B991'],
			}
		},
		mounted() {
			console.log('RenderJS mounted')
		},
		methods: {
			updateMessage(newValue, oldValue, ownerInstance, instance) {
				if (newValue && newValue.length) {
					newValue.forEach((item, index) => {
						if (item && item.length) {
							item.forEach((temp, indexa) => {
								const domea = document.getElementById(item[0]);
								const domeab = document.getElementById(item[1]);
								this.lineOptions.color = this.colorList[index]
								LeaderLine.setLine(domea, domeab, this.lineOptions);
							})
						}
					})
				}
			},
			handleTouchMove(event, ownerInstance) {
				// 处理触摸事件,比普通事件更高效
				console.log('Touch move:', event)
				// 可以向 Vue 组件发送数据
				ownerInstance.callMethod('onTouchMove', {
					x: event.touches[0].pageX,
					y: event.touches[0].pageY
				})
			}
		}
	}
</script>
<style>

</style>



<style>
	.container {
		position: relative;
		height: 400px;
		border: 1px solid #ddd;
	}

	.node {
		margin-top: 100rpx;
		margin-left: 100rpx;
		width: 80px;
		height: 366rpx;
		background: #3498db;
		border-radius: 8px;
		display: flex;
		align-items: center;
		justify-content: center;
		color: white;
	}

	.node:nth-child(1) {
		top: 50px;
		left: 100px;
	}

	.node:nth-child(2) {
		top: 200px;
		left: 300px;
	}
</style>

修改后

修改后代码

复制代码
<template>
	<view>
		<button @click="changeMessage">改变消息</button>
		<!-- RenderJS 模块 -->
		<view :change:prop="renderjs.updateMessage" :prop="lineList" @touchmove="renderjs.handleTouchMove">
			<!-- 使用 ref 绑定元素 -->
			<view style="display: flex;">
				<view :ref="dataList[0].id" :id="dataList[0].id" class="node">开始节点1</view>
				<view :ref="dataList[1].id" :id="dataList[1].id" class="node">开始节点2</view>
			</view>
			<view style="margin-left: 200rpx;" :ref="dataList[2].id" :id="dataList[2].id" class="node">结束节点</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	const dataList = ref([{
			id: 'startElement',
			text: 'abc'
		},
		{
			id: 'startElementa',
			text: 'def'
		},
		{
			id: 'endElement',
			text: 'ghi'
		},
	])
	const lineList = ref([
		['startElement', 'endElement'],
		['startElementa', 'endElement']
	])

	const changeMessage = () => {
		lineList.value = JSON.parse(JSON.stringify(lineList.value))
	}
</script>
<script module="renderjs" lang="renderjs">
	import LeaderLine from 'leader-line-vue'
	export default {
		data() {
			return {
				localData: 'RenderJS 数据',
				lineOptions: {
					color: '#34C759',
					size: 3,
					path: 'grid', // 使用网格路径  // grid  fluid
					startSocket: 'bottom',
					endSocket: 'top',
					endPlug: 'arrow1',
					gradient: true,
					startSocketGravity: [0, 1], // 向下
					endSocketGravity: [0, -1], // 向上
					dash: {
						animation: true
					},
				},
				colorList: ['#3498db', '#E6B991'],
			}
		},
		mounted() {
			console.log('RenderJS mounted')
		},
		methods: {
			updateMessage(newValue, oldValue, ownerInstance, instance) {
				if (newValue && newValue.length) {
					newValue.forEach((item, index) => {
						if (item && item.length) {
							item.forEach((temp, indexa) => {
								const domea = document.getElementById(item[0]);
								const domeab = document.getElementById(item[1]);
								this.lineOptions.color = this.colorList[index]
								LeaderLine.setLine(domea, domeab, this.lineOptions);
							})
						}
					})
				}
			},
			handleTouchMove(event, ownerInstance) {
				// 处理触摸事件,比普通事件更高效
				console.log('Touch move:', event)
				// 可以向 Vue 组件发送数据
				ownerInstance.callMethod('onTouchMove', {
					x: event.touches[0].pageX,
					y: event.touches[0].pageY
				})
			}
		}
	}
</script>
<style>

</style>



<style>
	.container {
		position: relative;
		height: 400px;
		border: 1px solid #ddd;
	}

	.node {
		margin-top: 100rpx;
		margin-left: 100rpx;
		width: 80px;
		height: 366rpx;
		background: #3498db;
		border-radius: 8px;
		display: flex;
		align-items: center;
		justify-content: center;
		color: white;
	}

	.node:nth-child(1) {
		top: 50px;
		left: 100px;
	}

	.node:nth-child(2) {
		top: 200px;
		left: 300px;
	}
</style>

主要在于

复制代码
startSocketGravity: [0, 1], // 向下
endSocketGravity: [0, -1], // 向上
相关推荐
郭老二8 小时前
【前端】vue3:编译步骤
前端
不在逃避q9 小时前
Trae/Vs Code/Cursor命令行无法跑npm命令
前端·arcgis·npm
夏殇之殁9 小时前
包中创建自定义列表项。 . 使用自定义列表项进行数据绑定 . 将天气预报数据保存到本地内存表,通过LiveBindings进行显示。 ...
服务器·前端·javascript
The Chosen One9859 小时前
高进度算法模板速记(待完善)
java·前端·算法
陈随易9 小时前
MoonBit抓包模块pcap,查看电脑的每一次联网通信
前端·后端·程序员
新中地GIS开发老师11 小时前
WebGIS开发学生作品|低空航天管理与航线规划系统
前端·javascript·webgis·三维gis开发
用户0595401744611 小时前
大模型对话记忆持久化踩坑实录:用 Playwright 自动化测了 300 次,终于揪出会话丢失的真凶
前端·css
丙氨酸長鏈11 小时前
Web前端入门第 问:JavaScript 一个简单的 IndexedDB 数据库入门示例
前端·javascript·数据库
kyriewen12 小时前
面试官让我手写虚拟列表——AI生成的版本,快速滚动几下就白屏了
前端·javascript·面试
IT_陈寒12 小时前
Vite热更新失效?你可能漏了这个配置
前端·人工智能·后端