vue+iview Using Tree Control
- 2021-09-11 19:33:09
- OfStack
vue+iview Use Tree Controls
1. Development Environment vue+iview
2. Computer System windows10 Professional Edition
3. In the process of using vue + iview development, we often use iview tree control, here I simply do a share, I hope to help you!
4. Add the following code to template:
<Scroll style="width: 100%" height="760">
<Tree
@on-select-change="chentreelick"
:data="treedata"
expand-node
></Tree>
</Scroll>
5. Add the following code to return:
treedata: [
{
title: "parent 1",
chenshow: false,
expand: true,
children: [
{
title: "parent 1-1",
chenshow: false,
expand: true,
children: [
{
title: "leaf 1-1-1",
chenshow: true,
},
{
title: "leaf 1-1-2",
chenshow: true,
selected: true,
},
],
},
{
title: "parent 1-2",
chenshow: false,
expand: true,
children: [
{
title: "leaf 1-2-1",
chenshow: true,
},
{
title: "leaf 1-2-1",
chenshow: true,
},
],
},
{
title: "parent 1-3",
chenshow: false,
expand: true,
children: [
{
title: "leaf 1-3-1",
chenshow: true,
},
{
title: "leaf 1-3-1",
chenshow: true,
},
],
},
{
title: "parent 1-4",
chenshow: false,
expand: true,
children: [
{
title: "leaf 1-4-1",
chenshow: true,
},
{
title: "leaf 1-4-1",
chenshow: true,
},
],
},
{
title: "parent 1-5",
chenshow: false,
expand: true,
children: [
{
title: "leaf 1-5-1",
chenshow: true,
},
{
title: "leaf 1-5-1",
chenshow: true,
},
],
},
{
title: "parent 1-6",
chenshow: false,
expand: true,
children: [
{
title: "leaf 1-6-1",
chenshow: true,
},
{
title: "leaf 1-6-1",
chenshow: true,
},
],
},
{
title: "parent 1-7",
chenshow: false,
expand: true,
children: [
{
title: "leaf 1-7-1",
chenshow: true,
},
{
title: "leaf 1-7-1",
chenshow: true,
},
],
},
{
title: "parent 1-8",
chenshow: false,
expand: true,
children: [
{
title: "leaf 1-8-1",
chenshow: true,
},
{
title: "leaf 1-8-1",
chenshow: true,
},
],
},
{
title: "parent 1-9",
chenshow: false,
expand: true,
children: [
{
title: "leaf 1-9-1",
chenshow: true,
},
{
title: "leaf 1-9-1",
chenshow: true,
},
],
},
],
},
],
5-1. Note the data bound in this return. Please refer to the official document of iview at the following address:
https://www.iviewui.com/components/tree
6. Add the following code to methods:
chentreelick(data) {
console.log(data);
console.log(" Clicked ");
console.log(data[0].chenshow);
},
// Attention : Parameter data, You can get the background data when you click , This data comes from the background , In actual development , We can Utilization data, Put what the background needs id Pass to Backstage