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

vue2+element-ui新增編輯表格+刪除行功能

 更新時(shí)間:2024年07月06日 10:49:11   作者:CiL#  
這篇文章主要介紹了vue2+element-ui新增編輯表格+刪除行功能,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧

vue2+element-ui新增編輯表格+刪除行

實(shí)現(xiàn)效果:

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

          <el-table :data="dataForm.updateData"
                    border
                    :header-cell-style="{'text-align':'center'}"
                    :cell-style="{'text-align':'center'}">
            <el-table-column label="選項(xiàng)字段"
                             align="center"
                             prop="name">
              <template slot-scope="scope">
                <el-form-item :prop="'updateData.' + scope.$index + '.formName'"
                              :rules="[
                                { required: true, message: '請(qǐng)輸入', trigger: 'blur' },
                                { min: 1, max: 20, message: '長(zhǎng)度在1到 20個(gè)字符', trigger: 'blur' }
                              ]">
                  <el-input v-model="scope.row.formName"
                            clearable></el-input>
                </el-form-item>
              </template>
            </el-table-column>
            <el-table-column fixed="right"
                             label="操作">
              <template slot-scope="scope">
                <el-button @click.native.prevent="addRow(scope.$index,scope.row,dataForm.updateData)"
                           type="text"
                           size="small">
                  新增
                </el-button>
                <el-button @click.native.prevent="deleteRow(scope.$index,scope.row,dataForm.updateData)"
                           type="text"
                           size="small"
                           v-if="dataForm.updateData.length!=1">
                  移除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
<script>
export default {
      data () {
        return {
            dataForm: {
                // 自定義字段
                updateData: [
                  {
                    // id: '',
                    formName: ''
                  }
                ]
                // 其他...    
            }
        }
      },
      methods: {
    // addRow 新增 自定義字段表格行
    addRow (index, rows, item) {
      // console.log(index, rows, item)
      // this.dataForm.updateData.push({
      //   // sort: this.dataForm.updateData && this.dataForm.updateData.length > 0 ? this.dataForm.updateData.length + 1 : 1,
      //   id: null,
      //   formName: ''
      // })
      // 數(shù)組中添加新元素
      item.splice(index + 1, 0, { formName: '' })
    },
    // deleteRow 刪除 自定義字段表格行
    deleteRow (index, rows, item) {
      // console.log(index, '當(dāng)前行索引', rows, '刪除的目標(biāo)行')
      // 從index這個(gè)位置開(kāi)始刪除數(shù)組后的1個(gè)元素
      item.splice(index, 1)
      // this.$confirm('刪除當(dāng)前行, 是否繼續(xù)?', '提示', {
      //   confirmButtonText: '確定',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // }).then(() => {
      //   item.splice(index, 1)
      //   // this.delArrId.push(rows.id) // 被刪除的id數(shù)組集合
      //   // rows.isDelete = 1
      // }).catch(() => {
      //   this.$message({
      //     type: 'info',
      //     message: '已取消刪除'
      //   })
      // })
    },
      }
}
</script>

補(bǔ)充:vue3+element-plus: el-table表格動(dòng)態(tài)添加或刪除行

vue3+element-plus: el-table表格動(dòng)態(tài)添加或刪除行

貼圖:

表格代碼:

添加代碼:

到此這篇關(guān)于vue2+element-ui新增編輯表格+刪除行的文章就介紹到這了,更多相關(guān)vue2 element-ui 新增表格內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論