绑定属性expanded,树自带方法this.$refs.tree.store.root.expanded,在mounted方法中给树方法赋值expandAll = false,具体代码实现详情如下:
html代码:
html
<template>
<el-tree
ref="tree"
:data="showDepData"
expand-on-click-node="false"
:props="{
label: 'name'
}"
node-key="deptId"
highlight-current
:default-expand-all="expanded"
@node-click="changeDepClick"
>
<span slot-scope="{ node, data }">
<i
v-if="node.level == 1"
style="margin-right: 4px"
class="wk wk-customer"
/>{{ data.name }}
</span>
</el-tree>
</template
js代码:
java
data(){
return{
expanded:false
}
}
mounted(){
//获取树自带的属性并给他赋值false
this.$refs.store.root.expanded = expanded
}