vue 点击添加多个input且与v-model绑定

2023-12-21 09:52:47
<template>
  <div>
    <tr v-for="(item, index) in formArr" :key="index">
      <td>
        <el-input v-model="item.value1" placeholder="请输入" />
      </td>
      <td>
        <el-input v-model="item.value2" placeholder="请输入" />
      </td>
      <td>
        <el-input v-model="item.value3" placeholder="请输入" />
      </td>
      <td>
        <i
          class="el-icon-circle-plus-outline"
          v-if="index === 0"
          @click="add"
        ></i>
        <i v-else class="el-icon-remove-outline" @click="del(index)"></i>
      </td>
    </tr>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formArr: [
        {
          value1: "",
          value2: "",
          value3: "",
        },
      ],
    };
  },
  methods: {
    add() {
      this.formArr.push({
        value1: "",
        value2: "",
        value3: "",
      });
    },
    del(index) {
      this.formArr.splice(index, 1);
    },
  },
};
</script>

<style lang="less" scoped>
.el-icon-circle-plus-outline,
.el-icon-remove-outline {
  margin-left: 10px;
  font-size: 30px;
  height: 100%;
  position: relative;
  top: 5px;
  cursor: pointer;
}
</style>

文章来源:https://blog.csdn.net/m0_70265923/article/details/135091806
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。