主体部分:
<el-table class="table" :data="Form3.list" tooltip-effect="dark" border style="width: 100%">
<el-table-column v-for="(item) in Form3.listTitle" :label="item.label" align="center">
<template slot-scope="scope">
<el-input-number v-model="scope.row[item.prop]" :min="0" :max="2" style="width: 115px;"></el-input-number>
</template>
</el-table-column>
</el-table>
Form3属性:
Form3: {
list: [],
listTitle: []
}
函数部分:
NumToList(val){
let num = parseInt(val);
let objStr = "";
let PropArr = [];
for (let i = 1; i < num + 1; i++) {
let obj = {};
obj.prop = "LOCK_NUM_" + i;
obj.label = "第" + i + "个";
PropArr.push(obj.prop);
this.Form3.listTitle.push(obj);
}
objStr += "{"
for (let i = 0; i < num; i++) {
objStr += PropArr[i] + ":0" + ",";
}
objStr = objStr.slice(0, objStr.length - 1);
objStr += "}";
let objList = eval('(' + objStr + ')');
this.Form3.list.push(objList);
}