Vue基于ElementUI实现Table可编辑/添加功能
文章目录效果预览前端代码添加和修改的js效果预览前端代码<el-table ref="singleTable" :data="dataList" border="" v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;"><el-ta...
·
效果预览
前端代码
<el-table ref="singleTable" :data="dataList" border="" v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;">
<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
<el-table-column v-for="(item ,idx) in tableList" :prop="item.value" width="100" header-align="center" align="center" :label="item.key">
<template slot-scope="scope">
<span v-if="scope.row.isEdit">
<form :rules="rules" ref="ruleForm">
<!--循环名称选则-->
<el-select filterable="" v-if="item.value == 'userId'" v-model="scope.row[item.value]" placeholder="请选择">
<el-option v-for="item in sysUserList" :key="item.id" :label="item.userName" :value="item.id">
</el-option>
</el-select>
<!--循环班次选则-->
<el-select multiple="" v-if="item.value != 'userId'" v-model="scope.row[item.value]" placeholder="请选择" prop="region" rules="rules.region">
<el-option v-for="item in workTimeShiftList" :key="item.id" :label="item.shiftName" :value="item.id">
</el-option>
</el-select>
</form> </span>
<span v-else=""> <p v-if="item.value == 'userId'"> <span v-for="allUserItem in allSysUserList"> </span></p><p v-if="scope.row[item.value] == allUserItem.id"> {{allUserItem.userName}} </p> </span>
<p></p>
<p v-if="item.value != 'userId'"> <span v-for="shiftId in scope.row[item.value]"> </span></p>
<p v-for="shifts in workTimeShiftList"> <span v-if="shiftId == shifts.id"> {{shifts.shiftName}} </span> </p>
<p></p>
<!--{{scope.row[item.value]}}-->
</template>
</el-table-column>
</el-table>
添加和修改的js
添加
var mydate = new Date();
var uuid = "worktime" + mydate.getDay() + mydate.getHours() + mydate.getMinutes() + mydate.getSeconds() + mydate.getMilliseconds();
this.dataList.push({
"id": uuid,
"isEdit": true
});
修改
for (var i = 0; i < this.dataList.length; i++) {
if (this.dataList[i].userId == this.dataListSelections[0].userId) {
this.dataList[i].isEdit = true;
this.dataList.splice(i, 1, this.dataList[i]) console.log("你即将修改 > ", this.dataList[i]) let param = {
id: this.dataList[i].userId,
userName: this.dataList[i].userName
}
this.sysUserList.push(param);
console.log(this.sysUserList) break;
}
}
更多推荐
已为社区贡献10条内容
所有评论(0)