新增组件-所有值为空时过滤
<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>
文章来源:https://www.toymoban.com/news/detail-672222.html
<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)
}
}
提交: 文章来源地址https://www.toymoban.com/news/detail-672222.html
function handleOk() {
const filteredList = form.namelist.filter((item) => {
const values = Object.values(item)
return !values.every((value) => value === '') //判断所有值为空
})
form.namelist = filteredList
}
到了这里,关于vue3-ts- element-plus新增组件-过滤的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!