<el-table :data="membersList" style="width: 100%"> <el-table-column type="index" label="序号" align="center" width="80"></el-table-column> <el-table-column label="考勤人员" align="center"> <el-table-column label="姓名" prop="memberName" align="center"></el-table-column> <el-table-column label="岗位" prop="post" align="center"></el-table-column> </el-table-column> <el-table-column label="出勤天数" prop="attendanceDays" align="center"></el-table-column> <el-table-column label="岗位系数" prop="postFactor" align="center"></el-table-column> <el-table-column label="调整系数" align="center"> <template slot-scope="scope"> <div> <el-input-number v-model="scope.row.adjustFactor" :precision="2" :step="0.01" :max="0.15" :min="-0.15" size="small" @change="changeFinal(scope.row)" ></el-input-number> </div> </template> </el-table-column> <el-table-column label="最终考勤天数" prop="finalDavs"></el-table-column> </el-table> <div class="membersDays"> <span>合计</span> <span>{{membersDaysJs}}</span>天 </div>computed: { membersDaysJs() { let num = 0; this.membersList.forEach(item => { if (item.finalDavs > 0) { num += item.finalDavs; } }); console.log(num); return num; } },
时间: 2023-07-06 14:26:35 浏览: 136
el-table-infinite-scroll:El-Table无限滚动
5星 · 资源好评率100%
根据您提供的代码,我发现您的`computed`选项写在了模板的后面,而不是Vue组件的选项中。您应该将`computed`选项移到Vue组件的选项中,像这样:
```
<template>
<div>
<el-table :data="membersList" style="width: 100%">
<!-- 表格列定义 -->
</el-table>
<div class="membersDays">
<span>合计</span>
<span>{{membersDaysJs}}</span>天
</div>
</div>
</template>
<script>
export default {
data() {
return {
// 数据定义
};
},
computed: {
membersDaysJs() {
let num = 0;
this.membersList.forEach(item => {
if (item.finalDavs > 0) {
num += item.finalDavs;
}
});
console.log(num);
return num;
}
},
methods: {
// 方法定义
}
};
</script>
```
这样应该可以解决computed不生效的问题。
阅读全文