vue+elementui實(shí)現(xiàn)動(dòng)態(tài)添加行/可編輯的table
本文實(shí)例為大家分享了vue+elementui實(shí)現(xiàn)動(dòng)態(tài)添加行、可編輯的table的具體代碼,供大家參考,具體內(nèi)容如下
HTMl代碼塊:
<el-col :span="24"> ? ? <el-form-item label="與承租戶同戶籍成員:" :label-width="formLabelWidth"> ? ? ? ? <el-table :data="zichandetail.members" :border=true style="width: 99.99%;"> ? ? ? ? ? ? <el-table-column type="index" label="序號(hào)" width="100"></el-table-column> ? ? ? ? ? ? <el-table-column prop="name" label="姓名" width="150"> ? ? ? ? ? ? ? ? <template slot-scope="scope"> ? ? ? ? ? ? ? ? ? ? <el-input v-model="scope.row.name" autocomplete="off" size="small" placeholder="請(qǐng)輸入姓名"></el-input> ? ? ? ? ? ? ? ? </template> ? ? ? ? ? ? </el-table-column> ? ? ? ? ? ? <el-table-column prop="name" label="與承租人關(guān)系" width="150"> ? ? ? ? ? ? ? ? <template slot-scope="scope"> ? ? ? ? ? ? ? ? ? ? <el-input v-model="scope.row.relationship" autocomplete="off" size="small" placeholder="請(qǐng)輸入與承租人關(guān)系"></el-input> ? ? ? ? ? ? ? ? </template> ? ? ? ? ? ? ?</el-table-column> ? ? ? ? ? ? ?<el-table-column prop="name" label="聯(lián)系電話" width="150"> ? ? ? ? ? ? ? ? ?<template slot-scope="scope"> ? ? ? ? ? ? ? ? ? ? ?<el-input v-model="scope.row.mobile" autocomplete="off" size="small" placeholder="請(qǐng)輸入聯(lián)系電話"></el-input> ? ? ? ? ? ? ? ? ?</template> ? ? ? ? ? ? ?</el-table-column> ? ? ? ? ? ? ?<el-table-column prop="name" label="出生年月" width="150"> ? ? ? ? ? ? ? ? ?<template slot-scope="scope"> ? ? ? ? ? ? ? ? ? ? ?<el-date-picker v-model="scope.row.birthday" type="month" placeholder="請(qǐng)輸入出生年月" value-format="yyyy-MM" size="small" class="allwidth"> ? ? ? ? ? ? ? ? ? ? ?</el-date-picker> ? ? ? ? ? ? ? ? ? </template> ? ? ? ? ? ? ? </el-table-column> ? ? ? ? ? ? ? <el-table-column prop="name" label="工作單位"> ? ? ? ? ? ? ? ? ? <template slot-scope="scope"> ? ? ? ? ? ? ? ? ? ? ? <el-input v-model="scope.row.gongzuodanwei" autocomplete="off" size="small" placeholder="請(qǐng)輸入工作單位"></el-input> ? ? ? ? ? ? ? ? ? </template> ? ? ? ? ? ? ? </el-table-column> ? ? ? ? ? ? ? <el-table-column label="操作" width="100"> ? ? ? ? ? ? ? ? ? <template slot-scope="scope"> ? ? ? ? ? ? ? ? ? ? ? <el-button size="mini" type="danger" plain @click="delmembers(scope.$index, scope.row)">刪除</el-button> ? ? ? ? ? ? ? ? ? </template> ? ? ? ? ? ? ? </el-table-column> ? ? ? ? ?</el-table> ? ? ? ? ?<i class="el-icon-circle-plus-outline" @click="addmembers"></i> ? ? ? </el-form-item> ? ?</el-col> </el-row>
js代碼塊:
1.添加操作
addmembers() {
? ?console.log('與承租戶同戶籍成員');
? ?var member = this.zichandetail.members;
? ?console.log(member);
? ?var length = member.length;
? ?this.zichandetail.members.push(
? ?{
? ? ? id: parseInt(length),
? ? ? name: '',
? ? ? relationship: '',
? ? ? mobile: '',
? ? ? birthday: '',
? ? ? gongzuodanwei: '',
? ?})
?},2.刪除操作
delmembers(index, row) {
? ?var that = this;
? ?this.$confirm('確認(rèn)刪除嗎?', '提示', {
? ?confirmButtonText: '確定',
? ?cancelButtonText: '取消',
? ?type: 'warning'
? ?}).then(() => {
? ? ? //點(diǎn)擊確定的操作(調(diào)用接口)
? ? ? var hasmembers = that.zichandetail.members;
? ? ? for (var i = 0; i < hasmembers.length; i++) {
? ? ? ? ? if (row.id == hasmembers[i].id) {
? ? ? ? ? ? ? that.zichandetail.members.splice(i, 1);
? ? ? ? ? ? ? // this.$message({ message: '刪除成功', duration: 2000, type: 'success' });
? ? ? ? ? ?}
? ? ? ?}
? ? ?}).catch(() => {
? ? ?//點(diǎn)取消的提示
? ? ? ? ?return;
? ? ?});
},實(shí)現(xiàn)效果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)未登錄訪問(wèn)其他頁(yè)面自動(dòng)跳轉(zhuǎn)登錄頁(yè)功能(實(shí)現(xiàn)步驟)
這篇文章主要介紹了vue實(shí)現(xiàn)未登錄下訪問(wèn)其他頁(yè)面自動(dòng)跳轉(zhuǎn)登錄頁(yè),本文分步驟給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-07-07
Vue項(xiàng)目通過(guò)node連接MySQL數(shù)據(jù)庫(kù)并實(shí)現(xiàn)增刪改查操作的過(guò)程詳解
最近在研究vue項(xiàng)目中使用node.js搭建server服務(wù)器,鏈接本地mysql數(shù)據(jù)庫(kù),進(jìn)行數(shù)據(jù)操作,下面這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目通過(guò)node連接MySQL數(shù)據(jù)庫(kù)并實(shí)現(xiàn)增刪改查操作的相關(guān)資料,需要的朋友可以參考下2022-05-05
使用Vue.js和MJML創(chuàng)建響應(yīng)式電子郵件
這篇文章主要介紹了使用Vue.js和MJML創(chuàng)建響應(yīng)式電子郵件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
Vue2.0實(shí)現(xiàn)將頁(yè)面中表格數(shù)據(jù)導(dǎo)出excel的實(shí)例
本篇文章主要介紹了Vue2.0實(shí)現(xiàn)將頁(yè)面中表格數(shù)據(jù)導(dǎo)出excel的實(shí)例,非常具有實(shí)用價(jià)值,感興趣的同學(xué)可以了解一下2017-08-08
vue實(shí)現(xiàn)移動(dòng)端H5數(shù)字鍵盤組件使用詳解
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)移動(dòng)端H5數(shù)字鍵盤組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08
Vue?入口與?initGlobalAPI實(shí)例剖析
這篇文章主要為大家介紹了Vue?入口與?initGlobalAPI實(shí)例剖析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08

