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 ...
随机推荐
- OpenIM集群(非k8s)部署文档
自行部署etcd/zookeeper/mysql/kafka/mongo/redis集群,可以根据此性能评估服务器需求. 以下是针对一台华为云主机s3的压测数据:8核16G内存,普通磁盘(非SSD)( ...
- C# Switch优雅写法
1 private static bool CanBeUpdateOrDel(bool 是否提交, bool 是否撤回, string 审核状态) => (是否提交, 是否撤回, 审核状态) s ...
- 学科知识图谱学习平台项目 :技术栈Java、Neo4j、MySQL等超详细教学
学科知识图谱学习平台项目 :技术栈Java.Neo4j.MySQL等超详细教学 0.效果展示 1.安装教程 安装Java SDK 11,下载前需要登录Oracle账号,下载链接,安装教程,测试是否能在 ...
- C++ Boost库 操作字符串与正则
字符串的查找与替换一直是C++的若是,运用Boost这个准标准库,将可以很好的弥补C++的不足,使针对字符串的操作更加容易. 字符串格式转换: #include <iostream> #i ...
- 曝iPhone 15系列将于9月13日发布 9月22日发售:7大升级、或售5999元起
按照往年惯例,新款iPhone将于9月中下旬(第三周)与大家见面.9to5Mac今日带来了新款iPhone的最新消息--iPhone 15系列将于9月13日发布,9月22日正式发售. 9to5Mac从 ...
- SpringBoot基于Spring Security的HTTP跳转HTTPS
简单说说 之所以采用Spring Security来做这件事,一是Spring Security可以根据不同的URL来进行判断是否需要跳转(不推荐), 二是不需要新建一个TomcatServletWe ...
- yapi 个人空间 这个分组的问题
总结:yapi个人空间分组的问题,我暂时不用理睬 他自己自由,但是 不允许他 创建非个人空间的分组.这点留意 避免不统一.所有的分组都必须我自己来创建,不允许他们私自创建.
- Java连接MySQL8.0样例代码
代码功能: 针对MySQL8.0,可以动态传入数据库连接信息(IP.端口.数据库.用户.密码).以及需要执行查询SQL. 注意:由于代码中打印表中的数据,所以最后在Main方法传入的参数是需要是查询的 ...
- NC19857 最后的晚餐(dinner)
题目链接 题目 题目描述 **YZ(已被和谐)的食堂实在是太挤辣!所以Apojacsleam现在想邀请他的一些好友去校外吃一顿饭,并在某酒店包下了一桌饭. 当Apojacsleam和他的同学们 ...
- NC26253 小石的妹子
题目链接 题目 题目描述 小石有 n 个妹子,每个妹子都有一个细心程度 \(a_i\)和一个热心程度 \(b_i\) , 小石想给她们一个重要程度 \(t_i\)(重要程度为 1 表示最重要,重要程 ...