vue3-ts- element-plus新增组件-过滤

 新增组件-所有值为空时过滤

 <el-form-item label="家庭成员">
        <div
          class="username-box"
          v-for="(item, index) in form.namelist"
          :key="index"
        >
          <div>
            姓名:
            <el-input v-model="item.name" placeholder="姓名"></el-input>
          </div>
          <div>
            性别:
            <el-select
              v-model="item.ger"
              class="m-2"
              placeholder="性别"
              size="large"
            >
              <el-option
                v-for="item in opget"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </div>
          <div>
            年龄:
            <el-input v-model="item.age" placeholder="年龄"></el-input>
          </div>
          <div>
            <el-button type="warning" @click.prevent="removeDomain(item)">
              删除
            </el-button>
          </div>
        </div>
        <div>
          <el-button
            type="success"
            :icon="Plus"
            circle
            @click="addDomain()"
          ></el-button>
        </div>
</el-form-item>

 

<style lang="less" scoped>
.username-box {
  display: flex;
  align-items: flex-end;
  div {
    margin-right: 10px;
    .el-input {
      width: 200px;
    }
  }
}
</style>
<script setup lang="ts">
import {  reactive  } from 'vue'
import { Plus, Check } from '@element-plus/icons-vue'
const form = reactive({
  namelist: [
    {
      name: '',
      age: '',
      ger: '',
    },
  ],
})
const opget = [
  { value: '0', label: '女' },
  { value: '1', label: '男' },
]
const addDomain = () => {
  console.log('添加成员')
  form.namelist.push({ name: '', age: '', ger: '' })
}
const removeDomain = (item) => {
  const index = form.namelist.indexOf(item)
  if (index !== -1) {
    form.namelist.splice(index, 1)
  }
}

提交: 

function handleOk() {
  const filteredList = form.namelist.filter((item) => {
    const values = Object.values(item)
    return !values.every((value) => value === '') //判断所有值为空
  })
  form.namelist = filteredList
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值