求每个total = FB2+FB4+PB1+PB3+PB5中属性的总和;
<el-table :data="tableContent" class="table_bsm"> <el-table-column v-for="(col, index) in tableHeader" :key="index" :prop="col.prop" :label="col.lable" align="center" min-width="100" > <template slot-scope="scope"> <span v-if="col.prop === 'lableName'"> {{ scope.row[col.prop] }} </span> <el-input v-else v-model.number="scope.row[col.prop]" placeholder="请输入内容" onkeyup="value=value.replace(/[^\d]/g,'')" :disabled="col.prop == 'total' ? true : false" @input="tableFTInput(scope.row, scope.$index)" /> </template> </el-table-column> </el-table>
data中需要声明
tableHeader:[]
tableContent:[]
内容入截图
/** * input 计算total值 * @param row 行数句 */ tableFTInput(row) { let noAddFiledArr = ["total", "lableName"] // 不需要相加计算total的值 if (row) { let totalVal = 0 for (const key in row) { let itemVal = row[key] if (!noAddFiledArr.includes(key)) { totalVal += itemVal * 1 } } row.total = totalVal } },