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

2. 代碼實現(xiàn)
<el-table v-loading="loading" :data="tableData" row-key="id">
<el-table-column property="id" label="序號"></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 實現(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 方法來處理哦!
});
}當(dāng)前情況呢 是適用于單條數(shù)據(jù)新增,并且直接操作數(shù)據(jù)庫的
到此這篇關(guān)于vue3+element Plus實現(xiàn)在table中增加一條表單數(shù)據(jù)的文章就介紹到這了,更多相關(guān)vue3 element Plus增加表單數(shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue3?element?plus?table?selection展示數(shù)據(jù),默認(rèn)選中功能方式
- element-plus的el-table自定義表頭篩選查詢功能實現(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(表格)點擊獲取對應(yīng)id方式
- vue3 elementplus table合并寫法
- Element?UI/Plus中全局修改el-table默認(rèn)樣式的解決方案
- ElementPlus?Table表格實現(xiàn)可編輯單元格
相關(guān)文章
vue搭建本地JSON靜態(tài)數(shù)據(jù)服務(wù)器全過程
這篇文章主要介紹了vue搭建本地JSON靜態(tài)數(shù)據(jù)服務(wù)器全過程,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07
利用Vite搭建Vue3+ElementUI-Plus項目的全過程
vue3如今已經(jīng)成為默認(rèn)版本了,相信大多數(shù)公司已經(jīng)全面擁抱vue3了,下面這篇文章主要給大家介紹了關(guān)于利用Vite搭建Vue3+ElementUI-Plus項目的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07
vue實現(xiàn)將一個數(shù)組內(nèi)的相同數(shù)據(jù)進(jìn)行合并
今天小編就為大家分享一篇vue實現(xiàn)將一個數(shù)組內(nèi)的相同數(shù)據(jù)進(jìn)行合并,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
VUE2 前端實現(xiàn) 靜態(tài)二級省市聯(lián)動選擇select的示例
下面小編就為大家分享一篇VUE2 前端實現(xiàn) 靜態(tài)二級省市聯(lián)動選擇select的示例。具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02

