人在爬坡 发表于 2023-9-26 20:00:28

vue~封装一个文本框添加与删除的组件

标签组件的效果如下


组件作用


[*]这是一个div,包含了两个文本框,后面是添加和删除按钮
[*]添加按钮复制出新的div,除了文本框没有内容,其它都上面一样
[*]删除按钮将当前行div删除
组件实现

<template>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><template v-for="(item,index) in tags">
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-row :gutter="4" >
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-col :span="8">
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-input v-model="item.authorName" placeholder="作者名称"/>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item></el-col>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-col :span="8">
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-input v-model="item.authorUnit" placeholder="作者单位名称"/>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item></el-col>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-col :span="4">
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-button type="text" @click="addAuthor">添加</el-button>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item>|
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-button type="text" @click="delAuthor(index)">删除</el-button>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item></el-col>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item></el-row>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item></template>
<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item>
</template>调用组件,为组件传默认值

<el-form-item label="作者信息" prop="articleAuthorList">
<author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
</el-form-item>测试代码

提交之后,将出现当前你添加的这个列表的对象,对接后端接口,将这个数组POST到后端即可,如图所示:



来源:https://www.cnblogs.com/lori/p/17730643.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: vue~封装一个文本框添加与删除的组件