vue使用el-table 添加行手動(dòng)填寫(xiě)數(shù)據(jù)和刪除行及提交保存功能
需求:點(diǎn)擊新增按鈕實(shí)現(xiàn)下列彈窗的效果,點(diǎn)擊添加行新增一行,點(diǎn)擊刪除進(jìn)行刪除行,點(diǎn)擊提交將數(shù)據(jù)傳遞到后端進(jìn)行保存。
代碼
<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="序號(hào)" 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="資產(chǎn)編號(hào)" 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">序號(hào)</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="字段長(zhǎng)度" 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{ //錄入數(shù)據(jù)字典資產(chǎn)信息 dataId: 1, //數(shù)據(jù)字典資產(chǎn)信息的集合 tableData: [], //數(shù)據(jù)字典資產(chǎn)信息錄入 openDataDictionary: false, //數(shù)據(jù)字典資產(chǎn)信息錄入彈出框標(biāo)題 titleDataDictionary: "", } }
methods
methods: { /** 刪除按鈕操作 */ handleDeleteDataDictionary(index, rows) { alert("index" + index);//這個(gè)index就是當(dāng)前行的索引坐標(biāo) this.$modal.confirm('是否刪除當(dāng)前行?').then(function () { rows.splice(index, 1); //對(duì)tableData中的數(shù)據(jù)刪除一行 }).then(() => { this.$modal.msgSuccess("刪除成功"); }).catch(() => { }); }, // 添加行 addDemo() { var d = { index: this.dataId++, assetNo: "", //資產(chǎn)編號(hào)實(shí)時(shí)回顯 riskSourceName: "", riskLevel: "", riskPointName: "", type: "", hiddenDanger: "", dangerLevel: "", accident: "", remark: "" }; this.tableData.push(d); setTimeout(() => { this.$refs.demoTable.setCurrentRow(d); }, 10); }, /** * 數(shù)據(jù)字典資產(chǎn)信息錄入點(diǎn)擊提交執(zhí)行的方法 * */ handleDataDictionaryAssetInfo() { addDataDictionaryAssetInfo(this.tableData).then(response => { this.$modal.msgSuccess("新增成功"); this.open = false; }); },
到此這篇關(guān)于vue采用el-table 添加行手動(dòng)填寫(xiě)數(shù)據(jù)和刪除行及提交的文章就介紹到這了,更多相關(guān)vue el-table 添加行刪除行內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue3中簡(jiǎn)單實(shí)現(xiàn)動(dòng)態(tài)添加路由
本文主要介紹了Vue3中簡(jiǎn)單實(shí)現(xiàn)動(dòng)態(tài)添加路由,,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05基于Vue.js實(shí)現(xiàn)數(shù)字拼圖游戲
為了進(jìn)一步讓大家了解Vue.js的神奇魅力,了解Vue.js的一種以數(shù)據(jù)為驅(qū)動(dòng)的理念,本文主要利用Vue實(shí)現(xiàn)了一個(gè)數(shù)字拼圖游戲,其原理并不是很復(fù)雜,下面跟著小編一起來(lái)學(xué)習(xí)學(xué)習(xí)。2016-08-08vue?動(dòng)態(tài)路由component?傳遞變量報(bào)錯(cuò)問(wèn)題解決
這篇文章主要為大家介紹了vue?動(dòng)態(tài)路由component?傳遞變量報(bào)錯(cuò)問(wèn)題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05vue調(diào)用微信JSDK 掃一掃,相冊(cè)等需要注意的事項(xiàng)
這篇文章主要介紹了vue調(diào)用微信JSDK 掃一掃,相冊(cè)等需要注意的事項(xiàng),幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下2021-01-01淺談vue使用axios的回調(diào)函數(shù)中this不指向vue實(shí)例,為undefined
這篇文章主要介紹了淺談vue使用axios的回調(diào)函數(shù)中this不指向vue實(shí)例,為undefined,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09Vue2+marked.js實(shí)現(xiàn)AI流式輸出的項(xiàng)目實(shí)踐
本文主要介紹了Vue2+marked.js實(shí)現(xiàn)AI流式輸出的項(xiàng)目實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2025-04-04Vue使用自定義指令實(shí)現(xiàn)拖拽行為實(shí)例分析
這篇文章主要介紹了Vue使用自定義指令實(shí)現(xiàn)拖拽行為,結(jié)合實(shí)例形式分析了Vue使用自定義指令實(shí)現(xiàn)拖拽行為具體步驟、原理與操作注意事項(xiàng),需要的朋友可以參考下2020-06-06解決VUE-Router 同一頁(yè)面第二次進(jìn)入不刷新的問(wèn)題
這篇文章主要介紹了解決VUE-Router 同一頁(yè)面第二次進(jìn)入不刷新的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07