翼度科技»论坛 编程开发 JavaScript 查看内容

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

4

主题

4

帖子

12

积分

新手上路

Rank: 1

积分
12
标签组件的效果如下


组件作用


  • 这是一个div,包含了两个文本框,后面是添加和删除按钮
  • 添加按钮复制出新的div,除了文本框没有内容,其它都上面一样
  • 删除按钮将当前行div删除
组件实现
  1. <template>
  2. <el-form-item label="作者信息" prop="articleAuthorList">
  3.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  4. </el-form-item>
  5. <el-form-item label="作者信息" prop="articleAuthorList">
  6.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  7. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  8.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  9. </el-form-item><template v-for="(item,index) in tags">
  10. <el-form-item label="作者信息" prop="articleAuthorList">
  11.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  12. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  13.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  14. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  15.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  16. </el-form-item><el-row :gutter="4" >
  17. <el-form-item label="作者信息" prop="articleAuthorList">
  18.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  19. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  20.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  21. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  22.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  23. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  24.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  25. </el-form-item><el-col :span="8">
  26. <el-form-item label="作者信息" prop="articleAuthorList">
  27.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  28. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  29.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  30. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  31.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  32. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  33.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  34. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  35.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  36. </el-form-item><el-input v-model="item.authorName" placeholder="作者名称"/>
  37. <el-form-item label="作者信息" prop="articleAuthorList">
  38.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  39. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  40.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  41. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  42.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  43. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  44.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  45. </el-form-item></el-col>
  46. <el-form-item label="作者信息" prop="articleAuthorList">
  47.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  48. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  49.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  50. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  51.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  52. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  53.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  54. </el-form-item><el-col :span="8">
  55. <el-form-item label="作者信息" prop="articleAuthorList">
  56.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  57. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  58.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  59. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  60.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  61. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  62.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  63. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  64.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  65. </el-form-item><el-input v-model="item.authorUnit" placeholder="作者单位名称"/>
  66. <el-form-item label="作者信息" prop="articleAuthorList">
  67.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  68. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  69.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  70. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  71.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  72. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  73.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  74. </el-form-item></el-col>
  75. <el-form-item label="作者信息" prop="articleAuthorList">
  76.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  77. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  78.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  79. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  80.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  81. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  82.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  83. </el-form-item><el-col :span="4">
  84. <el-form-item label="作者信息" prop="articleAuthorList">
  85.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  86. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  87.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  88. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  89.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  90. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  91.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  92. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  93.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  94. </el-form-item><el-button type="text" @click="addAuthor">添加</el-button>
  95. <el-form-item label="作者信息" prop="articleAuthorList">
  96.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  97. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  98.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  99. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  100.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  101. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  102.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  103. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  104.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  105. </el-form-item>|
  106. <el-form-item label="作者信息" prop="articleAuthorList">
  107.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  108. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  109.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  110. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  111.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  112. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  113.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  114. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  115.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  116. </el-form-item><el-button type="text" @click="delAuthor(index)">删除</el-button>
  117. <el-form-item label="作者信息" prop="articleAuthorList">
  118.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  119. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  120.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  121. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  122.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  123. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  124.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  125. </el-form-item></el-col>
  126. <el-form-item label="作者信息" prop="articleAuthorList">
  127.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  128. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  129.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  130. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  131.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  132. </el-form-item></el-row>
  133. <el-form-item label="作者信息" prop="articleAuthorList">
  134.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  135. </el-form-item><el-form-item label="作者信息" prop="articleAuthorList">
  136.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  137. </el-form-item></template>
  138. <el-form-item label="作者信息" prop="articleAuthorList">
  139.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  140. </el-form-item>
  141. </template>
复制代码
调用组件,为组件传默认值
  1. <el-form-item label="作者信息" prop="articleAuthorList">
  2.   <author-unit v-model="form.articleAuthorList" :dic="form.articleAuthorList"/>
  3. </el-form-item>
复制代码
测试代码

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



来源:https://www.cnblogs.com/lori/p/17730643.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具