vue+element-ui实现行数可控的表格输入
element的table中使用
<template slot-scope="scope">
</template>
包裹想要插入的input,或者select等HTML元素,<el-table>绑定一个的数组对象,在input或者select等HTML元素使用 v-model="scope.row.graduationSchool",graduationSchool为该HTML在table绑定数组对象的对应属性;这样就可以实现每一行的数据分别存储在table绑定数组对象的不同下标数组中。
新增一列时,只需要让table绑定数组对象push()一个与先前属性一致的空对象进去。
this.educationExperience.push({
// 毕业时间
graduationTime: '',
// 毕业院校
graduationSchool: '',
// 专业
major: '',
// 学历
degree: '',
// 学历性质
degreeNature: '',
// 学历编号
degreeNumber: '',
// 是否显示新增按钮
show: 'true',
});
完整代码:
<template>
<div class="test">
<el-card class="educationExperienceTable">
<span class="cardHeader">教育经历</span> <el-table :data="educationExperience"
stripe
border>
<el-table-column label="毕业时间">
<template slot-scope="scope">
<div class="educationExperienceDiv">
<el-date-picker v-model="scope.row.graduationTime"
placeholder=""
type="date"
value-format="yyyy-MM-dd">
</el-date-picker>
</div>
</template>
</el-table-column>
<el-table-column label="毕业院校">
<template slot-scope="scope">
<div class="educationExperienceDiv">
<el-input v-model="scope.row.graduationSchool"
placeholder="">
</el-input>
</div>
</template>
</el-table-column>
<el-table-column label="专业">
<template slot-scope="scope">
<div class="educationExperienceDiv">
<el-input v-model="scope.row.major"
placeholder="">
</el-input>
</div>
</template>
</el-table-column>
<el-table-column label="学历">
<template slot-scope="scope">
<div class="educationExperienceDiv">
<el-select v-model="scope.row.degree"
placeholder=""
clearable>
<el-option v-for="(item, index) in degreeList"
:key="index"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</div>
</template>
</el-table-column>
<el-table-column label="学历性质">
<template slot-scope="scope">
<div class="educationExperienceDiv">
<el-select v-model="scope.row.degreeNature"
placeholder=""
clearable>
<el-option v-for="(item, index) in degreeNatureList"
:key="index"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</div>
</template>
</el-table-column>
<el-table-column label="学历编号">
<template slot-scope="scope">
<div class="educationExperienceDiv">
<el-input v-model="scope.row.degreeNumber"
placeholder="">
</el-input>
</div>
</template>
</el-table-column>
<el-table-column label="操作"
width="136px">
<template slot-scope="scope">
<el-button type="success"
size="mini"
icon="el-icon-circle-plus-outline"
v-if="scope.row.show === 'true'"
plain
@click="pushNewEducation(scope.$index)">
</el-button>
<el-button type="danger"
size="mini"
icon="el-icon-delete"
plain
@click="deleteEducation(scope.$index)">
</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
</div>
</template>
HTML
<script>
export default {
data() {
return {
// 教育经历
educationExperience: [{
// 毕业时间
graduationTime: '',
// 毕业院校
graduationSchool: '',
// 专业
major: '',
// 学历
degree: '',
// 学历性质
degreeNature: '',
// 学历编号
degreeNumber: '',
// 是否显示新增按钮
show: 'true',
}],
// 可选学历列表
degreeList: [
{ label: '高中', value: '高中' },
{ label: '初中', value: '初中' },
{ label: '小学', value: '小学' },
],
// 可选学历性质
degreeNatureList: [
{ label: '小学升高中', value: '小学升高中' },
{ label: '初中升高中', value: '初中升高中' },
{ label: '高中升大学', value: '高中升大学' },
],
};
}, methods: {
// 添加新的教育经历
pushNewEducation(index) {
const list = this.educationExperience;
list[index].show = 'false';
list.push({
// 毕业时间
graduationTime: '',
// 毕业院校
graduationSchool: '',
// 专业
major: '',
// 学历
degree: '',
// 学历性质
degreeNature: '',
// 学历编号
degreeNumber: '',
// 是否显示新增按钮
show: 'true',
});
this.educationExperience = list;
},
// 删除教育经历
deleteEducation(index) {
const list = this.educationExperience;
if (index === 0 && list.length === 1) {
list.splice(index, 1);
list.push({
// 毕业时间
graduationTime: '',
// 毕业院校
graduationSchool: '',
// 专业
major: '',
// 学历
degree: '',
// 学历性质
degreeNature: '',
// 学历编号
degreeNumber: '',
// 是否显示新增按钮
show: 'true',
});
} else {
list.splice(index, 1);
}
if (index === list.length) {
list[index - 1].show = 'true';
}
list = this.educationExperience;
},
},
};
</script>
JS
<style lang="scss">
.test {
.educationExperienceTable {
.educationExperienceDiv {
width: 100%;
overflow: hidden;
border: 1px solid rgb(231, 227, 227);
border-radius: 10px;
.el-input__inner {
border: none;
}
}
}
.cardHeader {
font-weight: bold;
color: #606266;
display: block;
padding-bottom: 10px;
margin-bottom: 20px;
border-bottom: 1px solid rgb(211, 211, 211);
}
}
</style>
CSS
实现效果:

vue+element-ui实现行数可控的表格输入的更多相关文章
- Vue+Element UI 实现视频上传
一.前言 项目中需要提供一个视频介绍,使用户能够快速.方便的了解如何使用产品以及注意事项. 前台使用Vue+Element UI中的el-upload组件实现视频上传及进度条展示,后台提供视频上传AP ...
- 分享一个自搭的框架,使用Spring boot+Vue+Element UI
废弃,新的:https://www.cnblogs.com/hackyo/p/10453243.html 特点:前后端分离,可遵循restful 框架:后端使用Spring boot,整合了aop.a ...
- Vue + Element UI 实现权限管理系统
Vue + Element UI 实现权限管理系统 前端篇(一):搭建开发环境 https://www.cnblogs.com/xifengxiaoma/p/9533018.html
- vue + element ui 实现实现动态渲染表格
前言:之前需要做一个页面,能够通过表名动态渲染出不同的表格,这里记录一下.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9786326.html 网站地址:我的 ...
- vue + element ui 表格自定义表头,提供线上demo
前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...
- vue+element ui 的上传文件使用组件
前言:工作中用到 vue+element ui 的前端框架,使用到上传文件,则想着封装为组件,达到复用,可扩展.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9 ...
- vue+element ui 的表格列使用组件
前言:工作中用到 vue+element ui 的前端框架,有这个场景:很多表格的列有许多一样的,所以考虑将列封装为组件.转载请注明出处:https://www.cnblogs.com/yuxiaol ...
- vue+element ui 的tab 动态增减,切换时提示用户是否切换
前言:工作中用到 vue+element ui 的前端框架,动态添加 Tab,删除 Tab,切换 Tab 时提示用户是否切换等,发现 element ui 有一个 bug,这里记录一下如何实现.转载 ...
- 基于 vue+element ui 的cdn网站(多页面,都是各种demo)
前言:这个网站持续更新中...,有网上预览,github上也有源码,喜欢记得star哦,欢迎留言讨论. 网站地址:我的个人vue+element ui demo网站 github地址:yuleGH g ...
随机推荐
- 死磕 java集合之PriorityQueue源码分析
问题 (1)什么是优先级队列? (2)怎么实现一个优先级队列? (3)PriorityQueue是线程安全的吗? (4)PriorityQueue就有序的吗? 简介 优先级队列,是0个或多个元素的集合 ...
- bash语法
国际惯例打印hello world echo "hello world" 该程序运行结果: hello world 1.变量: a=;b="hello wor ...
- mybatis小结
mybatis是Apache的一个开源项目ibatis,后由Google管理,目前在github上.MyBatis 是支持定制化SQL.存储过程以及高级映射的优秀的持久层框架. 一.mybatis解决 ...
- Android 6.0 默认关闭定位和GPS,开启后默认选省电
默认关闭定位和GPS 修改位置 frameworks/base/packages/SettingsProvider/res/values/defaults.xml <string name=&q ...
- Git:四、连接GitHub远程仓库
1.拥有一个GitHub网站的账号 2.创建SSH Key 打开终端(Windows打开Git Bash),输入: ssh-keygen -t rsa -C "youremail@??.co ...
- 解决 win10飞行模式 无限自动开关 无法关闭
驱动问题,名为“Insyde Airplane Mode HID Mini-Driver”的驱动,这个驱动是专门用来快捷管理飞行模式的. 卸载完成后重启,无限开关飞行模式问题得到解决!
- MySQL和SQLyog的配置-安装及遇到的问题
1. 安装MySQL 我先是参考了菜鸟教程上的#Windows 上安装 MySQL #版块的安装教程,不过经历了种种磨难,我最后是按照#此篇博客#安装成功的. 这两篇教程最大的差别是在于下载的版本不同 ...
- windows创建域共享文件
windows创建域共享文件 windows常见的文件系统: FAT FAT32 NTFS NTFS的特点: 可以对单个文件或文件夹设置权限 支持更大的磁盘容量 支持加密和压缩 活动目录需要NTFS ...
- 怎么隐藏 iOS Safari 打开网页时的地址栏和工具栏探索
先来看一张截图 红色框处就是用手机浏览器打开页面时,自动显示出来的头部地址栏和底部工具栏 如果现在有一个需求,用手机浏览器打开页面时,把地址栏和工具栏隐藏,该怎么办呢? 起初我在度娘找到了好几篇博客都 ...
- 我所不知道的Makefile语法
问题一: $(CC) -c $^ -o $(ROOT_DIR)/$(OBJS_DIR)/$@ 这里的$^和$@是设么意思? 经过查找,该特殊符号的用法如下: 假如:all:library.cpp ma ...