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 ...
随机推荐
- windowsbat命令大全
Bat文件的创建及其命令大全 一.bat文件的创建 新建txt文本文件 向文本文件中输入命令 保存并修改文本文件后缀为.bat 双击保存后的bat文件,运行 二.bat命令大全 echo 和 @ @ ...
- py 学习(c++ to py)
py1: print 2024-01-27 23:18:57 星期六 #这里是注释 # py1 : 基础print总结 ''' aaa 有时候也用三个单引号当注释 但其实是字符串 交互式会输出 ''' ...
- vscode中文搜索乱码或搜索不到
使用vscode在全局搜索时,代码中的内容无法搜索出来,或者搜索出来是乱码. 经验证:与vscode的语言设置无关,设置为中文或英文都是一样的 后面猜想到会不会与文件自身的编码有关,因为我们项目中的代 ...
- c++基础之表达式
这次接着更新<c++ primer> 这本书的读书笔记,上一篇博文更新到了书中的第三章,本次将记录书中的第四章--表达式 左值与右值 在理解表达式之前需要先理解c++中左值和右值的概念. ...
- Linux 系统下查找文件命令
Linux 系统下查找文件命令,融合多部Linux经典著作,去除多余部分,保留实用部分. 查命令绝对路径: which用于查找并显示给定命令的绝对路径,环境变量中PATH参数也可以被查出来. [roo ...
- 从嘉手札<2023-11-27>
"我也没做错什么,放它去看海,总比跟着我好" 很多时候,悲伤总是细细的钻进心底 悄悄的生根发芽 待到了时机 它便如同一株参天巨树般郁郁葱葱 郁郁葱葱的令人发疯 人生本就像是做了一场 ...
- ChatGPT - 圈里的百科
ChatGPT(全名:Chat Generative Pre-trained Transformer),美国OpenAI [1] 研发的聊天机器人程序 [12] ,于2022年11月30日发布 [ ...
- 【OpenVINO™】在 MacOS 上使用 OpenVINO™ C# API 部署 Yolov5
在 MacOS 上使用 OpenVINO C# API 部署 Yolov5 项目介绍 YOLOv5 是革命性的 "单阶段"对象检测模型的第五次迭代,旨在实时提供高速.高精度的结果, ...
- AdoQuery 多列 查询 定位方法
frmClientDm.TopItemSkuShow_adoq.Locate('top_outer_iid;top_outer_sid', VarArrayOf([top_outer_iid,top_ ...
- 如何基于three.js(webgl)引擎架构,实现3D密集架库房,3D档案室(3d机器人取档、机器人盘点、人工查档、设备巡检)
前言: 这是最好的时代,也是最坏的时代:是充满挑战的时代,也是充满机遇的时代.是科技飞速的时代,也是无限可能的时代. 近年来,人工智能(AI)技术的飞速发展已经席卷了全球,不断突破着技术边界,为各行 ...