<template> <view> <text class="node" v-html="label"></text> <view class="children"> <tree-node v-for="(child, key) in children" :key="key" :treeData="child" /> </view> </view> </template> <script> export default { name: 'TreeNode', props: { treeData: { type: Object | Array, required: true } }, computed: { label() { return ` <u-row justify="center" gutter="10" style="display: flex;justify-content: center; margin: 10px"> <u-col span="4"></u-col> <u-col span="4"> <view style="color: red; background: orange; "> id: ${this.treeData.id} </view> </u-col> <u-col span="4"></u-col> </u-row> <u-row justify="center" gutter="10" style="display: flex;justify-content: center;"> <u-col span="4" style="border: 1px solid red; text-align: center; margin: 10rpx;"> <view> extendOne: ${this.treeData.extendOne} </view> </u-col> <u-col span="4" style="border: 1px solid red; text-align: center; margin: 10rpx;"> <view> extendTwo: ${this.treeData.extendTwo}, </view> </u-col> <u-col span="4" style="border: 1px solid red; text-align: center; margin: 10rpx;"> <view> extendThree: ${this.treeData.extendThree} </view> </u-col> </u-row> ` }, children() { const userExtendThree = this.treeData.userExtendThree if (userExtendThree) { return [userExtendThree] } else { return [] } } } } </script> <style lang="scss" scoped> .tree { font-size: 16px; } .node { display: inline-block; margin-right: 10px; padding: 5px; } .children { margin-left: 20px; } </style> 这个是数据结构 { "createBy": "13774", "createTime": "2023-05-22 16:48:21", "updateBy": "13774", "updateTime": "2023-05-22 17:32:17", "remark": null, "id": 13774, "userId": 13774, "extendOne": 13775, "extendTwo": 13776, "extendThree": 13777, "isLeader": null, "extendId": null, "userExtendThree": { "createBy": "", "createTime": null, "updateBy": "", "updateTime": null, "remark": null, "id": 13777, "userId": 13777, "extendOne": 13778, "extendTwo": 13779, "extendThree": 13780, "isLeader": null, "extendId": null, "userExtendThree": null } } 帮我把label()函数里面的css样式进行美化 使用行内样式。html结构不变只更改css,画成树状结构的,正方形画成圆形。每一层 用 左 右 中 线段展示关系层级
时间: 2023-07-19 18:03:04 浏览: 180
可以尝试将label()函数里的代码改为以下内容,来实现你想要的效果:
```
<label style="display: flex; flex-direction: row; align-items: center;">
<div style="border-radius: 50%; width: 30px; height: 30px; background-color: orange; color: white; display: flex; justify-content: center; align-items: center; margin-right: 10px;">{{ this.treeData.id }}</div>
<div style="border: 1px solid red; border-radius: 10px; padding: 10px; display: flex; flex-direction: row; justify-content: center;">
<div style="margin-right: 10px;">extendOne: {{ this.treeData.extendOne }}</div>
<div style="margin-right: 10px;">extendTwo: {{ this.treeData.extendTwo }}</div>
<div>extendThree: {{ this.treeData.extendThree }}</div>
</div>
</label>
<div style="display: flex; flex-direction: row; justify-content: center; align-items: center;">
<div style="height: 2px; background-color: red; flex: 1;"></div>
<div style="width: 10px; height: 10px; background-color: red; border-radius: 50%; margin: 0 5px;"></div>
<div style="height: 2px; background-color: red; flex: 1;"></div>
</div>
<div style="display: flex; flex-direction: row; justify-content: space-between; margin-top: 20px;">
<tree-node v-for="(child, key) in children" :key="key" :treeData="child" />
</div>
```
这里,我们使用了 label 标签来包裹节点的内容,并给该标签加上了行内样式,来实现圆形节点的效果。同时,我们添加了一个 div 标签,来展示节点之间的关系。最后,我们将子节点放置在一个 flex 布局的容器中,并设置了一个 margin-top 属性,来实现节点之间的间距。
阅读全文