vue使用el-table 添加行手動填寫數據和刪除行及提交保存功能
更新時間:2023年12月21日 14:16:19 作者:MXin5
遇到這樣的需求點擊新增按鈕實現下列彈窗的效果,點擊添加行新增一行,點擊刪除進行刪除行,點擊提交將數據傳遞到后端進行保存,怎么實現的呢,下面通過實例代碼給大家詳細講解,感興趣的朋友一起看看吧
需求:點擊新增按鈕實現下列彈窗的效果,點擊添加行新增一行,點擊刪除進行刪除行,點擊提交將數據傳遞到后端進行保存。
代碼
<el-dialog :title="titleDataDictionary" :visible.sync="openDataDictionary" width="1300px" append-to-body> <el-button type="primary" class="add-btn" @click="addDemo">添加行</el-button> <el-table :data="tableData" size="mini" stripe highlight-current-row border style="width: 97.3%" class="el-tb-edit" :header-cell-style="{ background: '#2a87ed', color: '#fff', fontSize: ' 1.2rem', fontWeight: 'normal', height: '2.88rem', }" ref="demoTable" > <el-table-column prop="index" label="序號" width="120"> <template slot-scope="scope"> <el-input v-model="scope.row.index"></el-input> <!-- <span>{{ scope.row.index }}</span> 顯示在輸入框的下面--> </template> </el-table-column> <el-table-column prop="assetNo" label="資產編號" width="120"> <template slot-scope="scope"> <el-input v-model="scope.row.assetNo"></el-input> </template> </el-table-column> <!-- <el-table-column type="index" width="50">序號</el-table-column> --> <el-table-column prop="riskSourceName" label="表中文名" width="120"> <template slot-scope="scope"> <el-input v-model="scope.row.riskSourceName"></el-input> </template> </el-table-column> <el-table-column prop="riskPointName" label="表英文名" width="120"> <template slot-scope="scope"> <el-input v-model="scope.row.riskPointName"></el-input> <!-- <span>{{ scope.row.riskPointName }}</span>--> </template> </el-table-column> <el-table-column prop="riskLevel" label="字段中文名" width="120"> <template slot-scope="scope"> <el-input v-model="scope.row.riskLevel"></el-input> <!-- <span>{{ scope.row.riskLevel }}</span>--> </template> </el-table-column> <el-table-column prop="hiddenDanger" label="字段類型" width="120"> <template slot-scope="scope"> <el-input v-model="scope.row.hiddenDanger"></el-input> <!-- <span>{{ scope.row.hiddenDanger }}</span>--> </template> </el-table-column> <el-table-column prop="type" label="字段長度" width="120"> <template slot-scope="scope"> <el-input v-model="scope.row.type"></el-input> <!-- <span>{{ scope.row.type }}</span>--> </template> </el-table-column> <el-table-column prop="accident" label="取值范圍" width="120"> <template slot-scope="scope"> <el-input v-model="scope.row.accident"></el-input> <!-- <span>{{ scope.row.accident }}</span>--> </template> </el-table-column> <el-table-column prop="remark" label="備注" width="120"> <template slot-scope="scope"> <el-input v-model="scope.row.remark"></el-input> <!-- <span>{{ scope.row.remark }}</span>--> </template> </el-table-column> <el-table-column prop="accident" label="操作" width="120"> <template slot-scope="scope"> <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteDataDictionary(scope.$index,tableData)" >刪除 </el-button> </template> </el-table-column> </el-table> <el-button type="primary" class="add-btn" @click="handleDataDictionaryAssetInfo">提交</el-button> </el-dialog>
data
data(){ return{ //錄入數據字典資產信息 dataId: 1, //數據字典資產信息的集合 tableData: [], //數據字典資產信息錄入 openDataDictionary: false, //數據字典資產信息錄入彈出框標題 titleDataDictionary: "", } }
methods
methods: { /** 刪除按鈕操作 */ handleDeleteDataDictionary(index, rows) { alert("index" + index);//這個index就是當前行的索引坐標 this.$modal.confirm('是否刪除當前行?').then(function () { rows.splice(index, 1); //對tableData中的數據刪除一行 }).then(() => { this.$modal.msgSuccess("刪除成功"); }).catch(() => { }); }, // 添加行 addDemo() { var d = { index: this.dataId++, assetNo: "", //資產編號實時回顯 riskSourceName: "", riskLevel: "", riskPointName: "", type: "", hiddenDanger: "", dangerLevel: "", accident: "", remark: "" }; this.tableData.push(d); setTimeout(() => { this.$refs.demoTable.setCurrentRow(d); }, 10); }, /** * 數據字典資產信息錄入點擊提交執(zhí)行的方法 * */ handleDataDictionaryAssetInfo() { addDataDictionaryAssetInfo(this.tableData).then(response => { this.$modal.msgSuccess("新增成功"); this.open = false; }); },
到此這篇關于vue采用el-table 添加行手動填寫數據和刪除行及提交的文章就介紹到這了,更多相關vue el-table 添加行刪除行內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
vue?動態(tài)路由component?傳遞變量報錯問題解決
這篇文章主要為大家介紹了vue?動態(tài)路由component?傳遞變量報錯問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-05-05淺談vue使用axios的回調函數中this不指向vue實例,為undefined
這篇文章主要介紹了淺談vue使用axios的回調函數中this不指向vue實例,為undefined,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09