欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue前端實(shí)現(xiàn)表格數(shù)據(jù)增查改刪功能

 更新時(shí)間:2024年05月10日 10:34:38   作者:崛起猩球@悟空  
增刪改查是我們寫項(xiàng)目百分之七十會(huì)遇到的代碼,下面這篇文章主要給大家介紹了關(guān)于vue前端實(shí)現(xiàn)表格數(shù)據(jù)增查改刪功能的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下

一、添加(增)-unshift首插入

1、【新增按鈕】添加點(diǎn)擊事件cilck;

<el-button @click="handleAdd()">添加</el-button>

2、點(diǎn)擊【新增按鈕】:

2.1、打開彈框;

2.2、內(nèi)容為空。

handleAdd() {
        this.dialogVisible = true
        this.addForm = {
          name: '',
          number: '',
          score: '',
          sex: ''
        }
      },

3、彈框【確定】:

3.1、動(dòng)態(tài)數(shù)據(jù)表格插入新增數(shù)據(jù);

3.2、全部數(shù)據(jù)表格插入新增數(shù)據(jù);

3.3、關(guān)閉彈框。

handleOk() {
        this.tableData.unshift(this.addForm)
        this.allData.unshift(this.addForm)
        this.dialogVisible = false
      }

二、搜索(查)-filter過濾

1、【查詢】按鈕添加點(diǎn)擊事件cilck;

<el-button type="primary" @click="handleSelect()">查詢</el-button>

2、點(diǎn)擊【查詢】:

2.1、姓名查詢:

 handleSelect() {
         this.tableData = this.allData.filter(item => {
            if (item.name.includes(this.formInline.name)) {
              return true
          }
        })
      }

2.2、學(xué)號(hào)查詢:

handleSelect() {
 this.tableData = this.allData.filter(item => {
            if (item.number === this.formInline.number) {
              return true
          }
        })
}

2.3、姓名+學(xué)號(hào)查詢:

 handleSelect() {
        //姓名+學(xué)號(hào)同時(shí)為空
        if (this.formInline.name === '' && this.formInline.number === '') {
          this.tableData = [...this.allData]
        } else if (this.formInline.name !== '' && this.formInline.number === '') {
          //姓名查詢,學(xué)號(hào)為空
          this.tableData = this.allData.filter(item => {
            if (item.name.includes(this.formInline.name)) {
              return true
            }
          })
        } else if (this.formInline.name === '' && this.formInline.number !== '') {
          //學(xué)號(hào)查詢,姓名為空
          this.tableData = this.allData.filter(item => {
            if (item.number === this.formInline.number) {
              return true
            }
          })
        } else if (this.formInline.name !== '' && this.formInline.number !== '') {
          //姓名+學(xué)號(hào)查詢,都不為空
          this.tableData = this.allData.filter(item => {
            if (item.name.includes(this.formInline.name) && item.number === this.formInline.number) {
              return true
            }
          })
        }
      }

三、編輯(改)-splice替換

1、【編輯】按鈕綁定點(diǎn)擊事件;

當(dāng)前行獲?。╯cope)。

<el-button type="success" plain size="small" @click="handleEdit(scope)">編輯</el-button>

2、點(diǎn)擊【編輯】:

  2.1、判斷為非添加(編輯)狀態(tài);

      2.1.1、彈框標(biāo)題為【編輯】;

      2.1.2、編輯狀態(tài)姓名不可編輯;

<el-form-item label="姓名">
          <el-input v-model="addForm.name" :disabled="isView || !isAdd"></el-input>
</el-form-item>

 2.2、解構(gòu)函數(shù):{...scope.row};為了后面獲取對象的index;

 2.3、打開彈框。

handleEdit(scope) {
        this.isView = false
        this.isAdd = false
        this.tkTitle = '編輯'
        this.addForm = { ...scope.row }
        this.dialogVisible = true
      },

3、點(diǎn)擊【確定】:

  3.1、判斷彈框狀態(tài)是【添加】or【編輯】;

  3.2、獲取index;

  3.3、找到表格index的一條,替換成修改后的當(dāng)前彈框數(shù)據(jù)。

4、關(guān)閉彈框。

 handleOk() {
        //添加確定
        if (this.isAdd) {
          this.tableData.unshift(this.addForm)
          this.allData.unshift(this.addForm)
          this.dialogVisible = false
        } else {
          //編輯確定
          const index = this.tableData.findIndex(item => {
            return item.name = this.addForm.name
          })
          if (index !== -1) {
            this.tableData.splice(index, 1, this.addForm)
          }
          this.dialogVisible = false
          this.allData = [...this.tabledata]
        }

四、刪除(刪)-splice刪除

1、【刪除】按鈕綁定點(diǎn)擊事件;

<el-button type="warning" plain size="small" @click="handleDelete(scope)">刪除</el-button>

2、點(diǎn)擊【刪除】:

 2.1、找到當(dāng)前行的index;

 2.2、刪除當(dāng)前index對應(yīng)的數(shù)據(jù)。

 handleDelete(scope) {
        const index = this.tableData.findIndex(item => {
          return item.name === scope.row.name
        })
        if (index !== -1) {
          this.tableData.splice(index, 1)
          this.allData =  [...this.tableData]
        }
      }

五、重置

1、【重置】添加點(diǎn)擊事件cilck;

<el-button @click="handleReset()">重置</el-button>

2、點(diǎn)擊【重置】:

2.1、查詢條件為空;

2.2、表格內(nèi)容顯示全部:運(yùn)用解構(gòu)函數(shù),allData數(shù)組淺拷貝給tableData數(shù)組。

handleReset() {
        this.formInline = {
          name: '',
          number: '',
          sex: ''
        }
        this.tableData = [...this.allData]
      }

六、查看

1、【查看】綁定點(diǎn)擊事件click;

顯示表格時(shí),當(dāng)前行數(shù)據(jù)的獲取:slot-scope="scope"

<template slot-scope="scope">
          <el-button type="primary" plain size="small" @click="handleView(scope)">查看</el-button>
</template>

2、點(diǎn)擊【查看】:

2.1、彈框是“查看”狀態(tài);

      2.1.1、彈框標(biāo)題顯示為“查看”;

      2.1.2、查看狀態(tài)下,內(nèi)容不可編輯;

2.2、彈框顯示當(dāng)前行數(shù)據(jù);

2.3、打開彈框。

:title="tkTitle"

:disabled="isView"
handleView(scope) {
        this.isView = true
        this.tkTitle = '查看'
        this.addForm = scope.row        
        this.dialogVisible = true
      }

總結(jié) 

到此這篇關(guān)于vue前端實(shí)現(xiàn)表格數(shù)據(jù)增查改刪功能的文章就介紹到這了,更多相關(guān)vue表格數(shù)據(jù)增查改刪內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue+elementUl導(dǎo)入文件方式(判斷文件格式)

    vue+elementUl導(dǎo)入文件方式(判斷文件格式)

    這篇文章主要介紹了vue+elementUl導(dǎo)入文件方式(判斷文件格式),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • 詳解Vue-cli中的靜態(tài)資源管理(src/assets和static/的區(qū)別)

    詳解Vue-cli中的靜態(tài)資源管理(src/assets和static/的區(qū)別)

    這篇文章主要介紹了Vue-cli中的靜態(tài)資源管理(src/assets和static/的區(qū)別,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • 淺析vue-router原理

    淺析vue-router原理

    這篇文章主要圍繞Vue的SPA單頁面設(shè)計(jì)展開。SPA(single page application):單一頁面應(yīng)用程序,有且只有一個(gè)完整的頁面,對vue router原理感興趣的朋友跟隨小編一起看看吧
    2018-10-10
  • Vue中的this.$emit()方法詳解

    Vue中的this.$emit()方法詳解

    這篇文章主要給大家介紹了關(guān)于Vue中this.$emit()方法的相關(guān)資料,this.$emit()是 Vue.js 中一個(gè)很有用的方法,可以幫助子組件向父組件傳遞事件,需要的朋友可以參考下
    2023-09-09
  • 淺談vue中resetFields()使用注意事項(xiàng)

    淺談vue中resetFields()使用注意事項(xiàng)

    這篇文章主要介紹了淺談vue中resetFields()使用注意事項(xiàng),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Vue實(shí)現(xiàn)注冊頁面的用戶交互詳解

    Vue實(shí)現(xiàn)注冊頁面的用戶交互詳解

    這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)注冊頁面的用戶交互的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),對我們深入掌握vue有一定的幫助,需要的小伙伴可以參考下
    2023-12-12
  • vue中漸進(jìn)過渡效果實(shí)現(xiàn)

    vue中漸進(jìn)過渡效果實(shí)現(xiàn)

    這篇文章主要為大家詳細(xì)介紹了vue中漸進(jìn)過渡效果的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • 利用vue實(shí)現(xiàn)模態(tài)框組件

    利用vue實(shí)現(xiàn)模態(tài)框組件

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)模態(tài)框組件的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • vite打包出現(xiàn)?"default"?is?not?exported?by?"node_modules/...問題解決辦法

    vite打包出現(xiàn)?"default"?is?not?exported?by?"

    這篇文章主要給大家介紹了關(guān)于vite打包出現(xiàn)?"default"?is?not?exported?by?"node_modules/...問題的解決辦法,文中通過代碼將解決的辦法介紹的非常詳細(xì),對同樣遇到這個(gè)問題的朋友具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2024-06-06
  • vue.js實(shí)現(xiàn)簡單計(jì)時(shí)器功能

    vue.js實(shí)現(xiàn)簡單計(jì)時(shí)器功能

    這篇文章主要為大家詳細(xì)介紹了vue.js實(shí)現(xiàn)簡單計(jì)時(shí)器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08

最新評(píng)論