背景:给el-tree的第一条数据增加默认选中效果
效果:在选中引力魔方的时候高亮第一个计划组
解决思路:当选中“引力魔方”的时候,通过key设置第一个计划组的选中状态,实现高亮效果
解决方法:
1、给计划组的树设置 node-key 属性,highlight-current高亮当前选中节点。
<div style="border-right: 1px solid #e2e8f0" :class="planGroupWidth" v-show="channelSelected3 == 'ylmfList' && channelAuth.includes('ylmfList')">
<p>选择计划组</p>
<div class="overflow-container">
<el-input placeholder="输入关键字搜索"
@keyup.enter.native="handleSearchPlanGroup"
v-model.trim="filterText1">
</el-input>
<el-tree class="single-level-tree"
@node-click="campaignGroupChange"
:data="planOptions[channelSelected3]"
:props="defaultProps1"
default-expand-all
:highlight-current="true"
node-key="campaignGroupId"
:filter-node-method="filterNode"
ref="tree1">
<span slot-scope="{ node, data }">
<span class="f-12">{{ data.campaignGroupName }}</span>
<span style="position: absolute;right: 10px;"><i class="el-icon-arrow-right"></i></span>
</span>
</el-tree>
</div>
</div>
2、监听选中渠道“引力魔方”时,通过el-tree的setCurrentKey方法去设置高亮
watch: {
channelSelected3: {
handler: function (val) {
if(val && val=='ylmfList') {
this.$nextTick(()=>{
this.$refs.tree1.setCurrentKey(this.planOptions['ylmfList'][0].campaignGroupId)
})
}
},
immediate: true
},
}
3、增加样式
.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
background-color: #ecf9fa!important;
}