<el-col :span="4" style="border-right: 0px solid rgba(70,166,255,0.37); min-height:500px;">
<h3>文章目录</h3>
<el-tree
class="filter-tree"
:data="doccata"
:props="defaultProps"
default-expand-all
@node-click="treeNodeClick"
ref="tree">
</el-tree>
</el-col>
<el-col :span="16">
<h3 style="text-align:center">{{document.name}}</h3>
<div v-for="(item,index) of doccata">
<div :id="item.id" class="right-zhang" :ref="item.id">
{{item.label}}
</div>
<div v-for="(item2,index2) of item.childrenNr" class="right-nr" :id="item2.id" :ref="item2.id">
{{item2.tiaoNr}}
</div>
</div>
</el-col>
getDetai(docId).then(response => {
let dataList=response.data.detailList
this.document=response.data.document
this.doccata=[];
let newZhangList=this.fn1(dataList)
newZhangList.forEach(item=>{
console.log(item)
let temp={};
temp.id=item.id+1000;
temp.label=item.zhangNr
let newZhang2List=this.fn2(dataList,item.zhangNr)
let children=[];
let childrenNr=[];
newZhang2List.forEach(item=>{
let temp={};
temp.id=item.id;
temp.label=item.zhang
children.push(temp)
childrenNr.push(item)
})
temp.children=children
temp.childrenNr=childrenNr
this.doccata.push(temp)
})
})
fn1(arr) {
const res = new Map();
return arr.filter(arr => !res.has(arr.zhangNr) && res.set(arr.zhangNr, arr.zhangNr));
},
fn2(arr,zhangNr) {
return arr.filter(arr => arr.zhangNr==zhangNr);
},
锚点跳转
//点击目录
treeNodeClick(data,node,el){
this.$refs[data.id][0].scrollIntoView(true)
},