在树形列表中
<el-table-column type="index" label="序号" width="55"> <template slot-scope="scope"> <!-- 父级 --> <div v-if="scope.row.hasOwnProperty('replaceType')"> {{ (searchGoods.pageNum-1) * searchGoods.pageSize + indexList[scope.$index] }} </div> </template> </el-table-column>
getProGoodsList() { this.fullscreenLoading = true; this.searchGoods.productId = this.nowRow.id; getProductGoodsPage(this.searchGoods).then((res) => { this.productGoodsList = res.data; this.goodsTotal = res.total; let indexList = []; const getIndex = (data, index) => {
// 获取indexList indexList.push(index + 1); if(data.replaceGoodsList && data.replaceGoodsList.length > 0){ data.replaceGoodsList.map((item, index) => getIndex(item, index)) } } this.productGoodsList.map((item, index) => getIndex(item, index)); this.indexList = indexList; }).finally(() => { this.fullscreenLoading = false; }); },