elementui 静态删除和新增按钮

在这里插入图片描述

<div>
                            <el-checkbox-group v-model="selectProductAttr[idx].values">
                                <div v-for="(item,index) in selectProductAttr[idx].options" style="display: inline-block"
                                     class="littleMarginLeft">
                                    <el-checkbox :label="item" :key="item"></el-checkbox>
                                    <el-button type="text" class="littleMarginLeft" @click="handleRemoveProductAttrValue(idx,index)">删除
                                    </el-button>
                                </div>
                            </el-checkbox-group>
                            <el-input v-model.trim="addProductAttrValue" style="width: 160px;margin-left: 10px" clearable></el-input>
                            <el-button class="littleMarginLeft" @click="handleAddProductAttrValue(idx)">增加</el-button>
                        </div>
   //手动添加商品属性
            handleAddProductAttrValue(idx){
    
    
                if(this.addProductAttrValue==null || this.addProductAttrValue==''){
    
    
                    this.$message.warning("属性值不能为空")
                }else if(this.selectProductAttr[idx].options.indexOf(this.addProductAttrValue)!== -1){
    
    
                    this.$message.warning("属性值不能重复")
                }else {
    
    
                    //手动添加
                    this.selectProductAttr[idx].options.push(this.addProductAttrValue);
                    //清空
                    this.addProductAttrValue='';
                }
            },
            //删除商品属性
            handleRemoveProductAttrValue(idx,index){
    
    
                this.selectProductAttr[idx].options.splice(index,1)
            },

猜你喜欢

转载自blog.csdn.net/jq1223/article/details/114948054