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 ...
随机推荐
- SpringCloud-06-Consul注册中心
Consul Server Consul 是由 HashiCorp 基于 Go 语言开发的,支持多数据中心,分布式高可用的服务发布和注册服务软件. 用于实现分布式系统的服务发现与配置. 使用起来也较 ...
- 【操作系统和计网从入门到深入】(四)基础IO和文件系统
前言 这个专栏其实是博主在复习操作系统和计算机网络时候的笔记,所以如果是博主比较熟悉的知识点,博主可能就直接跳过了,但是所有重要的知识点,在这个专栏里面都会提到!而且我也一定会保证这个专栏知识点的完整 ...
- C++小项目|2022期末大作业
前言 那么这里博主先安利一下一些干货满满的专栏啦! 手撕数据结构https://blog.csdn.net/yu_cblog/category_11490888.html?spm=1001.2014. ...
- 【算法】【回溯】两道经典排列问题OJ详解【力扣46 力扣47】【超详细的回溯算法教程】让我们牢牢把握回溯的精髓
[算法][回溯]两道经典排列问题OJ详解[力扣46 力扣47][超详细的回溯算法教程]让我们牢牢把握回溯的精髓 作者: @小小Programmer 这是我的主页:@小小Programmer 在食用这篇 ...
- Nginx的反向代理做负载均衡
对于一个大型网站,随着网站的访问量快速增长,单台服务器很难再支撑起需要,所以我们会购置多个服务器来满足业务量的需求,然后再利用Nginx提供的反向代理功能,来实现多台服务器间的协作功能,提高网站的处理 ...
- 由反射引出的Java动态代理与静态代理
写在开头 在<深入剖析Java中的反射,由浅入深,层层剥离!>这篇文章中我们讲反射时,曾提到过Java的动态代理中使用了反射技术,那么好,今天我们要就着反射的索引,来学习一下Java中的代 ...
- Linux如何禁用透明大页
环境: RHEL 6.5 + Oracle 11.2.0.4 RAC 1.确认透明大页是否开启 grep HugePage /proc/meminfo cat /sys/kernel/mm/redha ...
- MySQL-CDC原理与实践
MySQL CDC (Change Data Capture),中文名为MySQL变化数据捕获,是一种截取MySQL主从复制流中binlog的技术,从而实时捕获数据库中的增.删.改操作.在大数据.实时 ...
- Windows 10 快捷键大全|日常办公效率加倍
## 复制.粘贴及其他常规 Ctrl + X 剪切选定项. Ctrl + C(或 Ctrl + Insert) 复制选定项. Ctrl + V(或 Shift + Insert) 粘贴选定项. ...
- JS Leetcode 278. 第一个错误的版本 题解分析
壹 ❀ 引 本题来自LeetCode的278. 第一个错误的版本,难度简单,端午节就应该做点容易的题目缓解心情,题目描述如下: 你是产品经理,目前正在带领一个团队开发新的产品.不幸的是,你的产品的最新 ...