话不多说,直接上代码。想要实现的目的是这样的,想要在表格里单独添加每一个tag

那么,需要解决的问题就是如何定义这每一个插槽里的输入框,把每个输入框以及里面插入的数据区分开。

研究了很久,最后选择了对象数组。下面上代码

  1. <template>
  2. <div>
  3. <!-- 面包屑导航区域 -->
  4. <el-breadcrumb separator-class="el-icon-arrow-right">
  5. <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
  6. <el-breadcrumb-item>招标管理</el-breadcrumb-item>
  7. <el-breadcrumb-item>一键评标</el-breadcrumb-item>
  8. </el-breadcrumb>
  9. <!-- 卡片视图区域 -->
  10. <el-card>
  11. <!-- 添加角色按钮 -->
  12. <el-row>
  13. <el-col
  14. ><el-button type="primary" @click="addDialogVisible = true"
  15. >添加资质</el-button
  16. ></el-col
  17. >
  18. </el-row>
  19. <!-- 角色列表区域 -->
  20. <el-table :data="roleList" style="width: 100%" border stripe>
  21. <el-table-column type="index"></el-table-column>
  22. <el-table-column label="资质名称" prop="certiName"></el-table-column>
  23. <el-table-column label="等级" prop="level">
  24. <template slot-scope="scope">
  25. <el-tag
  26. v-for="item in scope.row.levels"
  27. :key="item.certiLevelId"
  28. closable
  29. :disable-transitions="false"
  30. @close="handleClose(item)"
  31. >
  32. {{ item.certiLevelName }}
  33. </el-tag>
  34. <el-input
  35. class="input-new-tag"
  36. v-if="inputParams[scope.$index].visible"
  37. v-model="inputParams[scope.$index].value"
  38. ref="saveTagInput"
  39. size="small"
  40. @keyup.enter.native="handleInputConfirm(scope.$index)"
  41. @blur="handleInputConfirm(scope.$index)"
  42. >
  43. </el-input>
  44. <el-button
  45. v-else
  46. class="button-new-tag"
  47. size="small"
  48. @click="showInput(scope.$index)"
  49. >添加资质</el-button
  50. >
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="操作" width="250px">
  54. <template slot-scope="scope">
  55. <el-button
  56. size="mini"
  57. type="warning"
  58. icon="el-icon-setting"
  59. @click="showEditDialog(scope.row.bidId)"
  60. >编辑名称</el-button
  61. >
  62. <el-button size="mini" type="danger" icon="el-icon-delete"
  63. >删除</el-button
  64. >
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. <!-- 分页区域 -->
  69. <el-pagination
  70. @size-change="handleSizeChange"
  71. @current-change="handleCurrentChange"
  72. :current-page="queryInfo.currentPage"
  73. :page-sizes="[1, 2, 5, 10]"
  74. :page-size="queryInfo.pageSize"
  75. layout="total, sizes, prev, pager, next, jumper"
  76. :total="total"
  77. >
  78. </el-pagination>
  79. </el-card>
  80. <!-- 添加角色列表对话框 -->
  81. <el-dialog
  82. title="添加项目"
  83. :visible.sync="addDialogVisible"
  84. width="50%"
  85. @close="addRoleDialogClosed"
  86. >
  87. <el-form
  88. ref="addRoleFormRef"
  89. :model="addRoleForm"
  90. :rules="addRoleFormRoles"
  91. width="50%"
  92. >
  93. <el-form-item label="资质名称" prop="bidName">
  94. <el-input v-model="addRoleForm.bidName"></el-input>
  95. </el-form-item>
  96. </el-form>
  97. <span slot="footer" class="dialog-footer">
  98. <el-button @click="addDialogVisible = false">取 消</el-button>
  99. <el-button type="primary" @click="addRole">确 定</el-button>
  100. </span>
  101. </el-dialog>
  102. <!-- 修改资质的对话框 -->
  103. <el-dialog
  104. title="修改资质名称"
  105. :visible.sync="editDialogVisible"
  106. width="50%"
  107. @close="editDialogclosed"
  108. >
  109. <el-form
  110. ref="editFormRef"
  111. :model="editForm"
  112. :rules="editFormRoles"
  113. width="50%"
  114. >
  115. <el-form-item label="资质名称" prop="bidName">
  116. <el-input v-model="editRoleForm.bidName"></el-input>
  117. </el-form-item>
  118. </el-form>
  119. <span slot="footer" class="dialog-footer">
  120. <el-button @click="editDialogVisible = false">取 消</el-button>
  121. <el-button type="primary">确 定</el-button>
  122. </span>
  123. </el-dialog>
  124. <!-- 修改等级的对话框 -->
  125. <el-dialog
  126. title="修改资质等级"
  127. :visible.sync="levelDialogVisible"
  128. width="50%"
  129. @close="levelDialogclosed"
  130. >
  131. <span slot="footer" class="dialog-footer">
  132. <el-button @click="levelDialogVisible = false">取 消</el-button>
  133. <el-button type="primary">确 定</el-button>
  134. </span>
  135. </el-dialog>
  136. </div>
  137. </template>
  138. <script>
  139. export default {
  140. data() {
  141. return {
  142. levelDialogVisible: false,
  143. editDialogVisible: false,
  144. addDialogVisible: false,
  145. total: 1,
  146. queryInfo: {
  147. currentPage: 1,
  148. pageSize: 10
  149. },
  150. inputVisible: {},
  151. editData: {},
  152. // 所有权限数据
  153. scoreList: [],
  154. roleList: [
  155. {
  156. certiName: '资质名称',
  157. levels: [
  158. {
  159. certiLevelId: 1,
  160. certiLevelName: '111'
  161. }
  162. ]
  163. },
  164. {
  165. certiName: '资质名称1',
  166. levels: [
  167. {
  168. certiLevelId: 1,
  169. certiLevelName: '111'
  170. }
  171. ]
  172. }
  173. ],
  174. roleForm: {},
  175. bidId: '',
  176. addRoleForm: {
  177. bidName: '',
  178. crtUserId: 1
  179. // roleDesc: ''
  180. },
  181. editRoleForm: {
  182. bidName: '',
  183. crtUserId: 1
  184. },
  185. levelRoleForm: {
  186. bidName: '',
  187. crtUserId: 1
  188. },
  189. editForm: {},
  190. levelForm: {},
  191. addRoleFormRoles: {
  192. bidName: [
  193. // 验证项目名称是否合法
  194. { required: true, message: '请输入项目名称', trigger: 'blur' }
  195. ]
  196. // roleDesc: [
  197. // // 验证创建人是否合法
  198. // { required: true, message: '请输入创建人', trigger: 'blur' }
  199. // ]
  200. },
  201. editFormRoles: {
  202. bidName: [
  203. // 验证项目名称是否合法
  204. { required: true, message: '请输入项目名称', trigger: 'blur' }
  205. ]
  206. },
  207. levelFormRoles: {
  208. bidName: [
  209. // 验证项目名称是否合法
  210. { required: true, message: '请输入项目等级', trigger: 'blur' }
  211. ]
  212. },
  213. // input
  214. inputParams: [
  215. {
  216. value: '',
  217. visible: false
  218. },
  219. {
  220. value: '',
  221. visible: false
  222. }
  223. ]
  224. }
  225. },
  226. created() {
  227. // this.getRoleList()
  228. },
  229. methods: {
  230. handleClose(item) {
  231. // item.certiLevelName.splice(
  232. // item.certiLevelName.indexOf(item.index),
  233. // 1
  234. // )
  235. },
  236. showInput(index) {
  237. this.inputParams[index].visible = true
  238. // console.log(
  239. // 'this.inputVisible',
  240. // this.inputVisible['visible' + row.index],
  241. // row.index
  242. // )
  243. // this.inputVisible = true
  244. // this.$nextTick(_ => {
  245. // // this.$refs.saveTagInput.$refs.input.focus()
  246. // this.$refs.saveTagInput.focus()
  247. // })
  248. },
  249. handleInputConfirm(index) {
  250. console.log(this.inputParams[index].value)
  251. this.roleList[index].levels.push({
  252. certiLevelId: Date.parse(new Date()) + '',
  253. certiLevelName: this.inputParams[index].value
  254. })
  255. this.inputParams[index].value = ''
  256. this.inputParams[index].visible = false
  257. // console.log('hhh', this.editData['input' + row.index])
  258. // let inputValue = this.editData['input' + row.index]
  259. // if (inputValue) {
  260. // row.levels.push(inputValue)
  261. // }
  262. // this.editData['input' + row.index] = ''
  263. // this.inputVisible['visible' + row.index] = false
  264. },
  265. showLevelDialog() {
  266. this.levelDialogVisible = true
  267. },
  268. editDialogclosed() {
  269. this.$refs.editFormRef.resetFields()
  270. },
  271. addRoleDialogClosed() {
  272. this.$refs.addRoleFormRef.resetFields()
  273. },
  274. levelDialogclosed() {
  275. this.$refs.levelFormRef.resetFields()
  276. },
  277. async showEditDialog(bidId) {
  278. // const { data: res } = await this.$http.get(`users/${id}`)
  279. // // const { data: res } = await this.$http.get('users/' + id)
  280. // if (res.meta.status !== 200) {
  281. // return this.$message.error('查询用户资料失败')
  282. // }
  283. // console.log(res.data)
  284. // this.editForm = res.data
  285. this.editDialogVisible = true
  286. },
  287. addRole() {
  288. this.$refs.addRoleFormRef.validate(async valid => {
  289. if (!valid) return
  290. const res = await this.$http.post('/bid', this.addRoleForm)
  291. console.log('增加', res)
  292. // 隐藏对话框
  293. this.addDialogVisible = false
  294. // 刷新列表
  295. this.getRoleList()
  296. })
  297. },
  298. handleSizeChange(newSize) {
  299. // console.log(newSize)
  300. this.queryInfo.pageSize = newSize
  301. this.getRoleList()
  302. },
  303. // 监听当前页改变的事件
  304. handleCurrentChange(newPage) {
  305. console.log(newPage)
  306. this.getUserList()
  307. },
  308. goBack() {
  309. this.$router.go(-1)
  310. },
  311. // 查询
  312. async getRoleList() {
  313. const { data: res } = await this.$http.get('/certi', {
  314. params: this.queryInfo
  315. })
  316. if (res.code !== 200) {
  317. return this.$message.console.error('查询资质失败')
  318. }
  319. console.log('查询资质', res)
  320. this.roleList = res.data.records
  321. this.roleList.forEach((item, index) => {
  322. item.index = index
  323. console.log('item.index,', item.index)
  324. this.editData['input' + item.index] = ''
  325. this.inputVisible['visible' + item.index] = false
  326. })
  327. this.total = res.data.total
  328. console.log(this.roleList)
  329. }
  330. }
  331. }
  332. </script>
  333. <style lang="scss" scoped>
  334. .el-tag {
  335. margin: 7px;
  336. }
  337. .bd_top {
  338. border-top: 1px solid #eee;
  339. }
  340. .bd_buttom {
  341. border-bottom: 1px solid #eee;
  342. }
  343. .vcenter {
  344. display: flex;
  345. align-items: center;
  346. }
  347. // .distributeDialog {
  348. // // height: 700px;
  349. // }
  350. </style>

关于elementUI如何在表格循环列表里分别新增Tag的设计使用的更多相关文章

  1. 在循环列表的富文本里摘出每个item的img标签内容(适合vue渲染)

    昨天在做公司项目的社区动态内容.后台接口返回的数据是数组套对象,对象里有富文本,然后需要摘出富文本里的img标签在列表里分开渲染(即图片九宫格样式).最终效果如图: 这个是后盾接口返回的json数据 ...

  2. Cocos2d-x3.0下实现循环列表

    本文的实现是參照我之前在做iOS时实现的一个能够循环的列表这里用C++重写一遍. 效果: 原文地址:http://blog.csdn.net/qqmcy/article/details/2739301 ...

  3. 微信小程序循环列表点击每一个单独添加动画

    首先,咱们看一下微信小程序动画怎么实现,我首先想到的是anime.js,但是引入之后用不了,微信小程序内的css也无法做到循环的动态,我就去找官方文档看看有没有相应的方法,哎,还真有 点击这里查看 微 ...

  4. Unity-UGUI-无限循环列表

    前言:项目准备新增一个竞技场排行榜,策划规定只显示0-400名的玩家.我一想,生成四百个游戏物体,怕不是得把手机给卡死?回想原来在GitHub上看到过一个实现思路就是无限循环列表,所以就想自己试试.公 ...

  5. 第 18 章 CSS 表格与列表

    学习要点: 1.表格样式 2.列表样式 3.其他功能 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 表格和列表,通过表格和列表的样式设置,让表格和列表显示更加多元化. 一.表格样式 表格有五 ...

  6. 循环列表的Java实现,解决约瑟夫环问题

    import java.util.Scanner; /** * 循环列表的Java实现,解决约瑟夫环问题 * * @author LIU * */ public class LinkedList { ...

  7. 第七十五节,CSS表格与列表

    CSS表格与列表 学习要点: 1.表格样式 2.列表样式 3.其他功能 一.表格样式 表格有五种独有样式,样式表如下:             属性               值           ...

  8. 微信小程序实现给循环列表点击添加类(单项和多项)

    在微信小程序里面没有DOM对象, 不能操作DOM. 所有的操作通过数据来实现,下面主要实现了给循环列表点击添加类的操作 一.单项 目标需求:实现下图,给点击的view增加类,每次只能选择一个. 主要思 ...

  9. 页面中php传值后循环列表js获取点击的id

    页面中php传值后循环列表js获取点击的id值进行js操作 <script type="text/javascript" src="__PUBLIC__/js/jq ...

随机推荐

  1. 匿名函数 =匿名方法+ lambda 表达式

    匿名函数的定义和用途 匿名函数是一个"内联"语句或表达式,可在需要委托类型的任何地方使用. 可以使用匿名函数来初始化命名委托[无需取名字的委托],或传递命名委托(而不是命名委托类型 ...

  2. 60天shell脚本计划-10/12-渐入佳境

    --作者:飞翔的小胖猪 --创建时间:2021年3月13日 --修改时间:2021年3月17日 说明 每日上传更新一个shell脚本,周期为60天.如有需求的读者可根据自己实际情况选用合适的脚本,也可 ...

  3. 小程序swiper高度自适应解决方案

    scroll-view 里面继续套一个 scroll-view ,设置纵向允许滚动 <swiper class="swiper"> <swiper-item> ...

  4. MySQL 学习-进阶

    MySQL高级学习 一.MySQL 事务 1.1.事务的概念 一条或多条 SQL 语句组成一个执行单元,其特点是这个单元要么同时成功要么同时失败,单元中的每条 SQL 语句都相互依赖,形成一个整体,如 ...

  5. Qt:QByteArray

    0.说明 QByteArray是存储二进制byte数组. 区别于QString:QByteArray中存储的全是byte,而QString中存储的全是16 bit Unicode码.QString是在 ...

  6. Leaflet:LayerGroup、FeatureGroup

    LayerGroup(Layer) Layer 用法:把一些Layer集中到一个组Group中,以便作为一个整体进行操作.如果把该Group加入到了Map中,任何从这个Group增加或者移除Layer ...

  7. SpringSecurity原理解析以及CSRF跨站请求伪造攻击

    SpringSecurity SpringSecurity是一个基于Spring开发的非常强大的权限验证框架,其核心功能包括: 认证 (用户登录) 授权 (此用户能够做哪些事情) 攻击防护 (防止伪造 ...

  8. python+pytest接口自动化(6)-请求参数格式的确定

    我们在做接口测试之前,先需要根据接口文档或抓包接口数据,搞清楚被测接口的详细内容,其中就包含请求参数的编码格式,从而使用对应的参数格式发送请求.例如某个接口规定的请求主体的编码方式为 applicat ...

  9. laravel redis操作大全

    字符串操作 普通得set/get操作,set操作,如果键名存在,则会覆盖原有得值 $redis = app("redis.connection"); $redis->set( ...

  10. 安装wkhtmltopdf

    思路 在网上查了下前后端都可以将html生成pdf,考虑到实现效果以及效率,最后决定将转化工作在服务端使用PHP完成.本着最好不要额外安装软件的原则,搜索过后分别尝试了 TCPDF MPDF FPDF ...