vue3+element Plus實(shí)現(xiàn)在table中增加一條表單數(shù)據(jù)的示例代碼
實(shí)現(xiàn)在table列表中,增加一行可單條數(shù)據(jù)保存的表單,使用vue3 + element Plus
1. 先上效果圖

2. 代碼實(shí)現(xiàn)
<el-table v-loading="loading" :data="tableData" row-key="id">
<el-table-column property="id" label="序號(hào)"></el-table-column>
<el-table-column property="name" label="姓名">
<template #default="scope">
<el-input v-if="!scope.row.id" v-model="scope.row.name"></el-input>
<span v-else>{{ scope.row.name }}</span>
</template>
</el-table-column>
<el-table-column property="number" label="年齡">
<template #default="scope">
<el-input v-if="!scope.row.id" v-model="scope.row.number"></el-input>
<span v-else>{{ scope.row.number }}</span>
</template>
</el-table-column>
<el-table-column label="操作" fixed="right" align="center" width="200">
<template #default="scope">
<el-button type="primary" size="small" v-if="!scope.row.id" @click.stop="handleSave(scope.row)">保存</el-button>
<el-button type="danger" size="small" v-if="scope.row.id" @click.stop="handleDelete(scope.row.id)">刪除</el-button>
</template>
</el-table-column>
</el-table>
<div class="bottom-btn">
<el-button type="success" @click="addLineData()">添加一行</el-button>
</div>ts 實(shí)現(xiàn)
/**添加一行數(shù)據(jù) */
function addLineData() {
const newData = {
name: '',
number: '',
};
tableData.value.push(newData);
}
/** */
function handleDelete() {
ElMessageBox.confirm("確認(rèn)刪除該條數(shù)據(jù)?", "警告", {
confirmButtonText: "確定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
//調(diào)用自己的接口啦!
// 當(dāng)然啦,如果全都是自己增加的未提交的數(shù)據(jù),可以使用splice 方法來(lái)處理哦!
});
}當(dāng)前情況呢 是適用于單條數(shù)據(jù)新增,并且直接操作數(shù)據(jù)庫(kù)的
到此這篇關(guān)于vue3+element Plus實(shí)現(xiàn)在table中增加一條表單數(shù)據(jù)的文章就介紹到這了,更多相關(guān)vue3 element Plus增加表單數(shù)據(jù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue3?element?plus?table?selection展示數(shù)據(jù),默認(rèn)選中功能方式
- element-plus的el-table自定義表頭篩選查詢功能實(shí)現(xiàn)
- Vue3+Element-Plus使用Table預(yù)覽圖片發(fā)生元素遮擋的解決方法
- vue3使用element-plus再次封裝table組件的基本步驟
- vue3使用elementPlus進(jìn)行table合并處理的示例詳解
- vue3+elementplus基于el-table-v2封裝公用table組件詳細(xì)代碼
- Vue3中Element Plus Table(表格)點(diǎn)擊獲取對(duì)應(yīng)id方式
- vue3 elementplus table合并寫法
- Element?UI/Plus中全局修改el-table默認(rèn)樣式的解決方案
- ElementPlus?Table表格實(shí)現(xiàn)可編輯單元格
相關(guān)文章
vue搭建本地JSON靜態(tài)數(shù)據(jù)服務(wù)器全過(guò)程
這篇文章主要介紹了vue搭建本地JSON靜態(tài)數(shù)據(jù)服務(wù)器全過(guò)程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
Vuex模塊化實(shí)現(xiàn)待辦事項(xiàng)的狀態(tài)管理
本文主要介紹了Vuex模塊化實(shí)現(xiàn)待辦事項(xiàng)的狀態(tài)管理的相關(guān)知識(shí),具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-03-03
利用Vite搭建Vue3+ElementUI-Plus項(xiàng)目的全過(guò)程
vue3如今已經(jīng)成為默認(rèn)版本了,相信大多數(shù)公司已經(jīng)全面擁抱vue3了,下面這篇文章主要給大家介紹了關(guān)于利用Vite搭建Vue3+ElementUI-Plus項(xiàng)目的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07
在vue中實(shí)現(xiàn)echarts隨窗體變化
這篇文章主要介紹了在vue中實(shí)現(xiàn)echarts隨窗體變化,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07
vue實(shí)現(xiàn)將一個(gè)數(shù)組內(nèi)的相同數(shù)據(jù)進(jìn)行合并
今天小編就為大家分享一篇vue實(shí)現(xiàn)將一個(gè)數(shù)組內(nèi)的相同數(shù)據(jù)進(jìn)行合并,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11
vue transition的延時(shí)播放實(shí)踐過(guò)程
文章介紹了如何使用JavaScript的`setTimeout`和Vue.js的`v-show`指令實(shí)現(xiàn)頁(yè)面自動(dòng)播放,并通過(guò)CSS的`transition`和`animation`屬性控制動(dòng)畫的播放時(shí)間2025-12-12
VUE2 前端實(shí)現(xiàn) 靜態(tài)二級(jí)省市聯(lián)動(dòng)選擇select的示例
下面小編就為大家分享一篇VUE2 前端實(shí)現(xiàn) 靜態(tài)二級(jí)省市聯(lián)動(dòng)選擇select的示例。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02

