最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue3實(shí)現(xiàn)表格編輯和刪除功能的示例代碼

 更新時(shí)間:2024年01月10日 10:15:56   作者:huoyueyi  
這篇文章主要為大家詳細(xì)介紹了vue3實(shí)現(xiàn)表格編輯和刪除功能的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

實(shí)現(xiàn)效果如下

實(shí)現(xiàn)代碼

<template>
    <div class="table">
      <div class="tableTop">現(xiàn)有數(shù)據(jù)集</div>
      <el-table
        :data="filterTableData"
        style="width: 100%"
        class-name="elTable"
      >
        <template #empty>
          <el-empty description="暫無(wú)數(shù)據(jù)" :image-size="200" />
        </template>
        <el-table-column label="模型創(chuàng)建日期" prop="date" />
        <el-table-column label="模型名稱" prop="name" />
        <el-table-column label="鏡像地址" prop="address" />
        <el-table-column align="right">
          <template #header>
            <el-input
              v-model="search"
              size="small"
              placeholder="請(qǐng)輸入您的模型名稱"
            />
          </template>
          <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
              >編輯</el-button
            >
            <el-button
              size="small"
              type="danger"
              @click="handleDelete(scope.$index)"
              >刪除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-dialog v-model="dialogVisible">
        <el-form :model="editingRowData">
          <el-form-item label="模型名稱">
            <el-input v-model="editingRowData.name" />
          </el-form-item>
        </el-form>
        <div slot="footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="handleUpdate">保存</el-button>
        </div>
      </el-dialog>
    </div>
</template>
 
<script setup>
import {
  ElInput,
  ElTable,
  ElTableColumn,
  ElIcon,
  ElButton,
  ElEmpty,
  ElMessageBox,
  ElMessage,
  ElDialog,
  ElForm,
  ElFormItem
} from 'element-plus'
 
import { computed, ref, reactive } from 'vue'
 
const search = ref('')
const editingRowData = ref({})
const dialogVisible = ref(false) // 編輯回顯時(shí)的彈窗
let editIndex = -1 // 表示沒有編輯的行
const tableData = reactive([
  {
    date: '2023-05-03',
    name: 'Tom',
    address: 'https://mirrors.aliyun.com/'
  },
  {
    date: '2023-05-02',
    name: 'John',
    address: 'http://mirrors.163.com/'
  },
  {
    date: '2023-05-04',
    name: 'Morgan',
    address: 'https://mirrors.hust.edu.cn/'
  },
  {
    date: '2023-05-01',
    name: 'Jessy',
    address: 'https://npm.taobao.org/'
  }
])
 
const handleEdit = (index, row) => {
  editIndex = index
  editingRowData.value = { ...row }
  dialogVisible.value = true
}
 
const handleUpdate = () => {
  if (editIndex !== -1) {
    tableData.splice(editIndex, 1, { ...editingRowData })
    dialogVisible.value = false
    // tableData.value = editingRowData.value  直接賦值會(huì)失敗,因?yàn)橹苯淤x值只是賦值,而這里需要一個(gè)對(duì)象
    tableData[editIndex] = Object.assign({}, editingRowData.value)
 
    ElMessage({
      type: 'success',
      message: '修改成功'
    })
  } else {
    ElMessage({
      type: 'error',
      message: '修改失敗!'
    })
  }
}
 
const filterTableData = computed(function () {
  return tableData.filter(function (data) {
    return (
      !search.value ||
      data.name.toLowerCase().includes(search.value.toLowerCase())
    )
  })
})
 
// 刪除數(shù)據(jù)集
const handleDelete = index => {
  ElMessageBox.confirm('您確定要?jiǎng)h除該數(shù)據(jù)嗎?', '警告', {
    confirmButtonText: '確定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    tableData.splice(index, 1)
    ElMessage({
      type: 'success',
      message: '刪除成功'
    })
  })
}
 
</script>

到此這篇關(guān)于vue3實(shí)現(xiàn)表格編輯和刪除功能的示例代碼的文章就介紹到這了,更多相關(guān)vue3表格編輯和刪除內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue2.0 常用的 UI 庫(kù)實(shí)例講解

    vue2.0 常用的 UI 庫(kù)實(shí)例講解

    這篇文章主要介紹了vue2.0 常用的 UI 庫(kù)實(shí)例講解,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-12-12
  • vuex新手進(jìn)階篇之a(chǎn)ctions的使用方法

    vuex新手進(jìn)階篇之a(chǎn)ctions的使用方法

    actions用來(lái)處理mutations中的異步操作,觸發(fā)mutations中的函數(shù),下面這篇文章主要給大家介紹了關(guān)于vuex新手進(jìn)階篇之a(chǎn)ctions的使用方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • vue+axios實(shí)現(xiàn)post文件下載

    vue+axios實(shí)現(xiàn)post文件下載

    這篇文章主要為大家詳細(xì)介紹了vue+axios實(shí)現(xiàn)post文件下載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • 淺析Vue為什么需要同時(shí)使用Ref和Reactive

    淺析Vue為什么需要同時(shí)使用Ref和Reactive

    這篇文章主要想來(lái)和大家一起探討一下Vue為什么需要同時(shí)使用Ref和Reactive,文中的示例代碼簡(jiǎn)潔易懂,感興趣的小伙伴可以跟隨小編一起了解一下
    2023-08-08
  • electron-vue?運(yùn)行報(bào)錯(cuò)?Object.fromEntries?is?not?a?function的解決方案

    electron-vue?運(yùn)行報(bào)錯(cuò)?Object.fromEntries?is?not?a?function

    Object.fromEntries()?是?ECMAScript?2019?新增的一個(gè)靜態(tài)方法,用于將鍵值對(duì)列表(如數(shù)組)轉(zhuǎn)換為對(duì)象,如果在當(dāng)前環(huán)境中不支持該方法,可以使用?polyfill?來(lái)提供類似功能,接下來(lái)通過本文介紹electron-vue?運(yùn)行報(bào)錯(cuò)?Object.fromEntries?is?not?a?function的解決方案
    2023-05-05
  • Vue子組件props從父組件接收數(shù)據(jù)并存入data

    Vue子組件props從父組件接收數(shù)據(jù)并存入data

    這篇文章主要介紹了Vue子組件props從父組件接收數(shù)據(jù)并存入data的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • vue實(shí)現(xiàn)接口封裝的實(shí)現(xiàn)示例

    vue實(shí)現(xiàn)接口封裝的實(shí)現(xiàn)示例

    本文主要介紹了vue實(shí)現(xiàn)接口封裝的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-11-11
  • vue?如何綁定disabled屬性讓其不能被點(diǎn)擊

    vue?如何綁定disabled屬性讓其不能被點(diǎn)擊

    這篇文章主要介紹了vue?如何綁定disabled屬性讓其不能被點(diǎn)擊,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • element中el-table表頭通過header-row-style設(shè)置樣式

    element中el-table表頭通過header-row-style設(shè)置樣式

    有些時(shí)候需要給element-ui表頭設(shè)置不同樣式,本文主要介紹了element中el-table表頭通過header-row-style設(shè)置樣式,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-01-01
  • apache和nginx下vue頁(yè)面刷新404的解決方案

    apache和nginx下vue頁(yè)面刷新404的解決方案

    這篇文章主要介紹了apache和nginx下vue頁(yè)面刷新404的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12

最新評(píng)論

岳普湖县| 梅河口市| 马边| 始兴县| 含山县| 高台县| 娱乐| 邵东县| 汉阴县| 广丰县| 鄂尔多斯市| 琼结县| 云安县| 博湖县| 桐梓县| 项城市| 达日县| 工布江达县| 龙胜| 容城县| 塔河县| 调兵山市| 方正县| 凤台县| 平遥县| 凉山| 凤翔县| 新干县| 柳州市| 张家港市| 青海省| 巨野县| 社旗县| 阿拉善左旗| 监利县| 长汀县| 滕州市| 固阳县| 麻栗坡县| 通榆县| 辰溪县|