vue动态生成索引列表

        <el-row
                    class="textarea_top"
                    v-for="(item, i) in trcList"
                    :key="item.Code + i"
                  >
                    <el-col :span="20">
                      <el-form-item
                        :label="item.Code + ':'"
                        label-width="100px"
                      >
                        <el-input
                          type="textarea"
                          :rows="2"
                          :disabled="isData"
                          resize="none"
                          v-model="item.Value"
                          autocomplete="off"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <template v-if="isData == false">
                      <el-col
                        :span="2"
                        class="pointer div_line_height div_padding"
                      >
                        <el-button size="mini" type="success" icon="el-icon-plus" plain @click="addTrc('trc', i)"></el-button>
                      </el-col>
                      <el-col :span="2" class="pointer div_line_height">
                        <el-button size="mini" type="primary" icon="el-icon-minus" plain @click="delTrc('trc', i)"></el-button>
                      </el-col>
                    </template>
                  </el-row>
                </div>

        data() {
	return {
	trcList: [{ Code: "RC1", Value: "", Type: 31 }],
}
},

 methods: {
	    /**
     * 添加 trc
     * @type 添加的是那个数组
     */
    addTrc(type, i) {
      if (type === "trc") {
        // 数组排序从小到大
        //  arr.sort((a,b)=> a.key - b.key);
        this.trcList.splice(i + 1, 0, {
          Code: `RC${this.trcList.length + 1}`,
          Value: null,
          Type: 31
        });
      }
    },

    /**
     * 删除
     * @type 删除的是那个数组
     * @i 被点击的索引
     */
    delTrc(type, i) {
      if (type === "trc") {
        if (this.trcList.length === 1) {
          return;
        }
        this.trcList.splice(i, 1);
        let arr = [];
        for (let i = 0; i < this.trcList.length; i++) {
          let newArr = {
            Code: `RC${i + 1}`,
            Value: this.trcList[i].Value,
            Type: this.trcList[i].Type
          };
          arr.push(newArr);
        }
        this.trcList = arr;
      }
    },

}
          
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值