公司项目用的renren-fast-vue,版本较低 element-ui是"2.8.2"版本的,表格配置属性 :default-expand-all=“true” 不生效
解决方法
HTML代码
<!-- 需要给table加一个v-if属性控制table销毁或初始化 -->
<el-table
v-if="isShowTable"
:data="dataList"
border
v-loading="dataListLoading"
row-key="deptId"
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
</el-table>
data() {
return {
isShowTable: true, // 默认为true
dataList:[]
};
},
watch: {
// 监听表格数据
dataList: function () {
this.$nextTick(() => {
this.expandAll()
})
}
},
//触发的方法
/**
* 触发所有展开图标的click事件
*/
expandAll () {
// 获取点击的箭头元素
let els = document.getElementsByClassName('el-table__expand-icon')
for (let i = 0; i < els.length; i++) {
els[i].click()
}
},
/**
* 展开所有下级
*/
unFoldAll () {
this.isShowTable = false
this.$nextTick(function () {
this.isShowTable = true
let _this = this
window.setTimeout(function () {
_this.expandAll()
}, 300)
})
},
/**
* 收起所有下级
*/
foldAll () {
this.isShowTable = false
this.$nextTick(function () {
this.isShowTable = true
})
}