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 實(shí)現(xiàn)拖拽動(dòng)態(tài)生成組件的需求
這篇文章主要介紹了vue 如何實(shí)現(xiàn)拖拽動(dòng)態(tài)生成組件的需求,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下2021-05-05Vue-cli集成axios請(qǐng)求出現(xiàn)CORS跨域問(wèn)題及解決
這篇文章主要介紹了Vue-cli集成axios請(qǐng)求出現(xiàn)CORS跨域問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,2023-10-10VuePress在build打包時(shí)window?document?is?not?defined問(wèn)題解決
這篇文章主要為大家介紹了VuePress在build打包時(shí)window?document?is?not?defined問(wèn)題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07Vue遞歸組件+Vuex開發(fā)樹形組件Tree--遞歸組件的簡(jiǎn)單實(shí)現(xiàn)
這篇文章也是我自己開發(fā)的從無(wú)到有的過(guò)程,所以它可以為你提供一些Tree組件開發(fā)的思路,本文重點(diǎn)給大家介紹vue遞歸組件的簡(jiǎn)單實(shí)現(xiàn),感興趣的朋友跟隨小編一起看看吧2019-04-04Vue實(shí)現(xiàn)兄弟組件間的聯(lián)動(dòng)效果
這篇文章主要介紹了Vue實(shí)現(xiàn)兄弟組件間的聯(lián)動(dòng)效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01