:deciduous_tree: Vue2樹形圖組件html
npm i vue-tree-chart --save
in template:前端
<TreeChart :json="treeData" />
in script:vue
import TreeChart from "vue-tree-chart";
export default {
components: {
TreeChart
},
data() {
return {
treeData: {
...
}
}
}
...
組件數據,支持字段:node
- name[String] 節點名稱
- image_url[String] 節點圖片
- children[Array] 節點後代
- mate[Object] 節點配偶
示例:npm
{
name: 'root',
image_url: "https://static.refined-x.com/avat.jpg",
children: [
{
name: 'children1',
image_url: "https://static.refined-x.com/avat1.jpg"
},
{
name: 'children2',
image_url: "https://static.refined-x.com/avat2.jpg",
mate: {
name: 'mate',
image_url: "https://static.refined-x.com/avat3.jpg"
},
children: [
{
name: 'grandchild',
image_url: "https://static.refined-x.com/avat.jpg"
},
{
name: 'grandchild2',
image_url: "https://static.refined-x.com/avat1.jpg"
},
{
name: 'grandchild3',
image_url: "https://static.refined-x.com/avat2.jpg"
}
]
},
{
name: 'children3',
image_url: "https://static.refined-x.com/avat.jpg"
}
]
}
點擊節點觸發,接收當前節點數據爲參數json
npm run serve
npm run build-bundle
Copyright (c) 2017-present, 前端路上bash