vue实现简单多规格

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

一、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)
      },
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大可-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值