el-tree切换图标
时间: 2023-10-15 08:05:24 浏览: 94
要切换 el-tree 中节点的图标,可以通过在节点数据中设置 icon 属性或使用 scoped slot 自定义节点的内容来实现。具体做法如下:
1. 在节点数据中设置 icon 属性:
```
<template>
<el-tree :data="data">
<span slot-scope="{ node }">
{{ node.label }}
<span :class="node.icon"></span>
</span>
</el-tree>
</template>
<script>
export default {
data() {
return {
data: [
{
label: '节点一',
icon: 'el-icon-s-promotion'
},
{
label: '节点二',
icon: 'el-icon-s-management'
}
]
};
}
};
</script>
```
2. 使用 scoped slot 自定义节点的内容:
```
<template>
<el-tree :data="data">
<template slot-scope="{ node }">
<span :class="node.icon"></span>
{{ node.label }}
</template>
</el-tree>
</template>
<script>
export default {
data() {
return {
data: [
{
label: '节点一',
icon: 'el-icon-s-promotion'
},
{
label: '节点二',
icon: 'el-icon-s-management'
}
]
};
}
};
</script>
```
以上两种方式都可以实现节点图标的切换。
阅读全文
相关推荐

















