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("確認刪除該條數(shù)據(jù)?", "警告", { confirmButtonText: "確定", cancelButtonText: "取消", type: "warning", }).then(() => { //調(diào)用自己的接口啦! // 當然啦,如果全都是自己增加的未提交的數(shù)據(jù),可以使用splice 方法來處理哦! }); }
當前情況呢 是適用于單條數(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ù),默認選中功能方式
- element-plus的el-table自定義表頭篩選查詢功能實現(xiàn)
- Vue3+Element-Plus使用Table預(yù)覽圖片發(fā)生元素遮擋的解決方法
- vue3使用element-plus再次封裝table組件的基本步驟
- vue3使用elementPlus進行table合并處理的示例詳解
- vue3+elementplus基于el-table-v2封裝公用table組件詳細代碼
- Vue3中Element Plus Table(表格)點擊獲取對應(yīng)id方式
- vue3 elementplus table合并寫法
- Element?UI/Plus中全局修改el-table默認樣式的解決方案
- ElementPlus?Table表格實現(xiàn)可編輯單元格
相關(guān)文章
Vue-cli集成axios請求出現(xiàn)CORS跨域問題及解決
這篇文章主要介紹了Vue-cli集成axios請求出現(xiàn)CORS跨域問題及解決方案,具有很好的參考價值,希望對大家有所幫助,2023-10-10VuePress在build打包時window?document?is?not?defined問題解決
這篇文章主要為大家介紹了VuePress在build打包時window?document?is?not?defined問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07Vue遞歸組件+Vuex開發(fā)樹形組件Tree--遞歸組件的簡單實現(xiàn)
這篇文章也是我自己開發(fā)的從無到有的過程,所以它可以為你提供一些Tree組件開發(fā)的思路,本文重點給大家介紹vue遞歸組件的簡單實現(xiàn),感興趣的朋友跟隨小編一起看看吧2019-04-04