element_ui实现表格内套表单,点击可以编辑
<template>
<div class="app-container">
<el-table :data="list" stripe style="width: 100%" @cell-dblclick="openEditColumn">
<el-table-column prop="cameraX" label="坐标位置:X">
<template slot-scope="scope">
<span v-show="!scope.row.xEdit">{{ scope.row.cameraX }}</span>
<el-input @blur="editColumnData(scope.row, 'cameraX')"
@keyup.enter.native="editColumnData(scope.row, 'cameraX')" v-show="scope.row.xEdit"
size="mini" v-model="scope.row.cameraX"></el-input>
</template>
</el-table-column>
<el-table-column prop="cameraY" label="坐标位置:Y">
<template slot-scope="scope">
<span v-show="!scope.row.yEdit">{{ scope.row.cameraY }}</span>
<el-input @blur="editColumnData(scope.row, 'cameraY')"
@keyup.enter.native="editColumnData(scope.row, 'cameraY')" v-show="scope.row.yEdit"
size="mini" v-model="scope.row.cameraY"></el-input>
</template>
</el-table-column>
<el-table-column prop="cameraZ" label="坐标位置:Z">
<template slot-scope="scope">
<span v-show="!scope.row.zEdit">{{ scope.row.cameraZ }}</span>
<el-input @blur="editColumnData(scope.row, 'cameraZ')"
@keyup.enter.native="editColumnData(scope.row, 'cameraZ')" v-show="scope.row.zEdit"
size="mini" v-model="scope.row.cameraZ"></el-input>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
export default {
name: "handleViewCamera",
components: {},
props: {
},
data() {
return {
list: {},
};
},
created() {
},
mounted() {
this.getList();
},
methods: {
// 获取数据列表
getList() {
queryList(this.regionId).then((res) => {
res.data.cameras.forEach(item => {
item.xEdit = false;
item.yEdit = false;
item.zEdit = false;
this.list.push(item)
});
});
},
// 打开信息编辑
openEditColumn(row, column, cell, event) {
if (column.property === "cameraX") {
this.equipmentList.cameras.forEach(item => {
if (item.id === row.id) {
// 激活当前点击的单元格进入可以编辑(span与el-input标签显示隐藏切换)
item.xEdit = true
}
});
} else if (column.property === "cameraY") {
this.equipmentList.cameras.forEach(item => {
if (item.id === row.id) {
item.yEdit = true
}
});
} else if (column.property === "cameraZ") {
this.equipmentList.cameras.forEach(item => {
if (item.id === row.id) {
item.zEdit = true
}
});
}
},
// 表格数据编辑保存并关闭编辑
editColumnData(row, column) {
// 关闭表格编辑
this.list.forEach(item => {
if (item.id === row.id) {
if (column === "cameraX") {
item.xEdit = false;
} else if (column === "cameraY") {
item.yEdit = false;
} else if (column === "cameraZ") {
item.zEdit = false;
}
}
});
}
},
};
但是表单大在小和表格不同,比较不自然,可以设样式来解决:以下为参考
在需要套表单输入框的表格列中,使用 scoped slot 的方式来渲染表格单元格。例如:
<template slot-scope="scope">
<el-form>
<el-form-item>
<el-input :border="false" v-model="scope.row.data"></el-input>
</el-form-item>
</el-form>
</template>
<template slot-scope="scope">
<el-form>
<el-form-item>
<el-input :border="false" v-model="scope.row.data"></el-input>
</el-form-item>
</el-form>
</template>
在 el-input 组件中添加 :border="false" 属性,来设置输入框无边框。 根据表格列的宽度,调整 el-form 和 el-input 的宽度,使其与表格列一致。例如: <template slot-scope="scope">
<el-form :style="{width: scope.col.width + 'px'}">
<el-form-item :style="{marginBottom: '0'}">
<el-input :border="false" v-model="scope.row.data" :style="{width: (scope.col.width - 20) + 'px'}"></el-input>
</el-form-item>
</el-form>
</template>
<template slot-scope="scope">
<el-form :style="{width: scope.col.width + 'px'}">
<el-form-item :style="{marginBottom: '0'}">
<el-input :border="false" v-model="scope.row.data" :style="{width: (scope.col.width - 20) + 'px'}"></el-input>
</el-form-item>
</el-form>
</template>
在上述代码中,使用了 scope.col.width 来获取当前表格列的宽度,并根据表格列的宽度来设置 el-form 和 el-input 的宽度。其中,减去了 20 像素的宽度,是为了留出一定的空隙,使得输入框和表格列之间有一定的间距。 最后,将以上代码加入到 el-table-column 中,即可实现表格里面套表单输入框的效果。例如:
<el-table-column prop="data" label="数据">
<template slot-scope="scope">
<el-form :style="{width: scope.col.width + 'px'}">
<el-form-item :style="{marginBottom: '0'}">
<el-input :border="false" v-model="scope.row.data" :style="{width: (scope.col.width - 20) + 'px'}"></el-input>
</el-form-item>
</el-form>
</template>
</el-table-column>
<el-table-column prop="data" label="数据">
<template slot-scope="scope">
<el-form :style="{width: scope.col.width + 'px'}">
<el-form-item :style="{marginBottom: '0'}">
<el-input :border="false" v-model="scope.row.data" :style="{width: (scope.col.width - 20) + 'px'}"></el-input>
</el-form-item>
</el-form>
</template>
</el-table-column>
希望这可以帮助您完成 Element_ui 表格里面套表单输入框的功能。
element_ui实现表格内套表单,点击可以编辑的更多相关文章
- layui数据表格使用(一:基础篇,数据展示、分页组件、表格内嵌表单和图片)
表格展示神器之一:layui表格 前言:在写后台管理系统中使用最多的就是表格数据展示了,使用表格组件能提高大量的开发效率,目前主流的数据表格组件有bootstrap table.layui table ...
- Bootstrap -- 表格样式、表单布局
Bootstrap -- 表格样式.表单布局 1. 表格的一些样式 举例: <!DOCTYPE html> <html> <head> <meta http- ...
- Bootstrap 表单和图片 (内联表单,表单合组,水平排列,复选框和单选框,下拉列表,校验状态,添加额外的图标,控制尺寸,图片)
一.表单 基本格式 注:只有正确设置了输入框的 type 类型,才能被赋予正确的样式. 支持的输入框控件 包括:text.password.datetime.datetime-local.date.m ...
- bootstrap 基础表单 内联表单 横向表单
bootstrap 基础表单 内联表单 横向表单 <!DOCTYPE html> <html> <head> <title></title> ...
- Bootstrap3 表单-输出内联表单
为 <form> 元素添加 .form-inline 类可使其内容左对齐并且表现为 inline-block 级别的控件.只适用于视口(viewport)至少在 768px 宽度时(视口宽 ...
- selenium - switch_to.frame()- 内嵌表单的切换
表单嵌套frame/iframe webDriver只能在一个页面上对元素识别和定位,对于frame/iframe表单内嵌页面上的元素无法直接定位,此时就需要通过switch_to.frame()方法 ...
- js动态的往表格中加入表单元素
效果如图: 这里我用的是layui的静态表格,其他框架也是一样的(只要你都表单元素要通过js进行渲染),我的需求是在表单中放了表格的元素,表格中还有表单的元素.表格中的行数据是js动态添加的,正常的添 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表单:内联表单
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 1、前端--HTML简介、head内常见标签、body内常见标签(特殊符号、div、span、a、img、列表、表格table、表单form)、标签两大属性
今日内容 HTML简介 HTML是构造网页的骨架>>>:几乎所有的网站都是由HTML构建而成 HTML:超文本标记语言 # 不是一门编程语言 没有任何的逻辑 只有固定的标记功能 &q ...
- Day46(列表标签,表格标签,表单标签,css的引入方式,css选择器)
一.列表标签 列表标签分为三种. 1.无序列表<ul>,无序列表中的每一项是<li> 英文单词解释如下: ul:unordered list,“无序列表”的意思. li:lis ...
随机推荐
- window hadoop yarn任务执行失败:ExitCodeException exitCode=-1073741515
环境 window server 2019 单机版hadoop3.3.1 和 winutils.exe 异常 winutils.exe task create -m -1 -c -1 continer ...
- org.apache.hadoop.security.AccessControlException: Queue root.online already has 0 applications, cannot accept submission of application
org.apache.hadoop.security.AccessControlException: Queue root.online already has 0 applications, can ...
- Load-balanced-online-OJ-system 负载均衡的OJ系统项目
前言 那么这里博主先安利一些干货满满的专栏了! 首先是博主的高质量博客的汇总,这个专栏里面的博客,都是博主最最用心写的一部分,干货满满,希望对大家有帮助. 高质量博客汇总 本项目Github地址 - ...
- 【STL源码剖析】stack_queue底层模拟实现 | 什么是适配器?【超详细的底层注释和解释】
今天博主继续带来STL源码剖析专栏的第四篇博客了! 今天带来stack和queue的模拟实现!话不多说,直接进入我们今天的内容! 前言 那么这里博主先安利一下一些干货满满的专栏啦! 手撕数据结构htt ...
- idea 集成接口测试插件
idea api集成接口测试 日常逼逼叨 相信很多后端开发接口的小伙伴们在开发完成后也会进行简单的测试,可能会用到apifox,postman之类的测试工具,但是up近期发现了一个比较好用的idea插 ...
- 将实体光盘制作成光盘映像iso文件
春节假期整理历史物件时发现一些书籍的光盘,虽然买了多年但一直没有看过,因为自己在用的电脑都没有光驱.正好老爸的电脑是带光驱的,想着趁过节把这些光盘的内容读取出来存在NAS上方便后续使用. 使用Ultr ...
- 多个Nginx进程运行导致配置加载失效问题
多个Nginx进程运行导致配置加载失效问题 问题描述 在用nginx进行接口代理时,修改配置文件后,重新加载nginx,却发现无论怎么修改配置文件,都无法生效,接口一直无法代理成功.查看了之前做的接口 ...
- 吉特日化MES & 日化制药工厂信息化系统架构图
作者:情缘 出处:http://www.cnblogs.com/qingyuan/ 关于作者:从事仓库,生产软件方面的开发,在项目管理以及企业经营方面寻求发展之路 版权声明:本文版权归作者和博客园 ...
- JS LeetCode 1423. 可获得的最大点数简单题解
壹 ❀ 引 最近也是浮躁的很,一篇redux的文章写了三千多字才算写了一半...写的泪目了.还是刷刷算法静下心,顺带记录下算法做题过程吧.今天的题来自LeetCode每日打卡,题目出自LeetCode ...
- P2P通讯方式
概述 实现p2p通讯我们提供两种方式,这两种方式分别是通过客户端直接互通和p2p映射: 无论哪一种,首先设备两端都得部署好fastnat客户端,NAT类型不能是对称类型NAT(Symmetric),否 ...