实现效果图、代码可直接拿来使用

一、template代码

<el-table :data="tableData" style="width: 100%">
          <el-table-column align="center" label="id" prop="id" width="180" />
          <el-table-column align="center" label="名称" width="180">
            <template slot-scope="scope">
              <el-input v-model="scope.row.name" placeholder="规格名称" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="库存" width="180">
            <template slot-scope="scope">
              <el-input v-model="scope.row.inventory" placeholder="库存" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="限购">
            <template slot-scope="scope">
              <el-input v-model="scope.row.quota" placeholder="限购" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="划线价">
            <template slot-scope="scope">
              <el-input v-model="scope.row.crossedPrice" placeholder="划线价" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="售价">
            <template slot-scope="scope">
              <el-input v-model="scope.row.price" placeholder="售价" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="结算价">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.settlementPrice"
                placeholder="结算价"
              />
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <el-popover
                :ref="`popover-${scope.$index}`"
                placement="left"
                trigger="click"
                width="260"
              >
                <p>确定删除改规格吗?</p>
                <div style="text-align: center">
                  <el-button size="mini" @click="quxiao(scope)">取消</el-button>
                  <el-button
                    size="mini"
                    type="danger"
                    @click="deleteRow(scope, tableData)"
                  >
                    确定
                  </el-button>
                </div>
                <div style="cursor: pointer; color: #3054eb" slot="reference">
                  删除
                </div>
              </el-popover>
            </template>
          </el-table-column>
        </el-table>
        <el-button
          style="margin-top: 10px; margin-bottom: 10px"
          type="primary"
          @click="increase"
        >
          添加
        </el-button>

二、js代码

data() {
i: 0,
tableData: [],
}

methods: {
      quxiao(ee) {
        ee._self.$refs[`popover-${ee.$index}`].doClose()
      },
      deleteRow(ee, row) {
        this.$confirm(`确定要删除改规格吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then( () => {
            row.splice(ee.$index,1)
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '您取消了删除',
            })
          })
        ee._self.$refs[`popover-${ee.$index}`].doClose()

      },
      
      increase() {
        this.i ++
        let hh = {
          id: this.i,
          name: '',
          inventory: '',
          quota: '',
          crossedPrice: '',
          price: '',
          settlementPrice: ''
        }
        this.tableData.push(hh)
      },
}

GitHub 加速计划 / vu / vue
207.54 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:2 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 4 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 5 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐