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实现行数可控的表格输入的更多相关文章

  1. Vue+Element UI 实现视频上传

    一.前言 项目中需要提供一个视频介绍,使用户能够快速.方便的了解如何使用产品以及注意事项. 前台使用Vue+Element UI中的el-upload组件实现视频上传及进度条展示,后台提供视频上传AP ...

  2. 分享一个自搭的框架,使用Spring boot+Vue+Element UI

    废弃,新的:https://www.cnblogs.com/hackyo/p/10453243.html 特点:前后端分离,可遵循restful 框架:后端使用Spring boot,整合了aop.a ...

  3. Vue + Element UI 实现权限管理系统

    Vue + Element UI 实现权限管理系统 前端篇(一):搭建开发环境 https://www.cnblogs.com/xifengxiaoma/p/9533018.html

  4. vue + element ui 实现实现动态渲染表格

    前言:之前需要做一个页面,能够通过表名动态渲染出不同的表格,这里记录一下.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9786326.html 网站地址:我的 ...

  5. vue + element ui 表格自定义表头,提供线上demo

    前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...

  6. vue+element ui 的上传文件使用组件

    前言:工作中用到 vue+element ui 的前端框架,使用到上传文件,则想着封装为组件,达到复用,可扩展.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9 ...

  7. vue+element ui 的表格列使用组件

    前言:工作中用到 vue+element ui 的前端框架,有这个场景:很多表格的列有许多一样的,所以考虑将列封装为组件.转载请注明出处:https://www.cnblogs.com/yuxiaol ...

  8. vue+element ui 的tab 动态增减,切换时提示用户是否切换

    前言:工作中用到 vue+element ui 的前端框架,动态添加 Tab,删除 Tab,切换 Tab 时提示用户是否切换等,发现 element ui  有一个 bug,这里记录一下如何实现.转载 ...

  9. 基于 vue+element ui 的cdn网站(多页面,都是各种demo)

    前言:这个网站持续更新中...,有网上预览,github上也有源码,喜欢记得star哦,欢迎留言讨论. 网站地址:我的个人vue+element ui demo网站 github地址:yuleGH g ...

随机推荐

  1. .net core 并发下的线程安全问题

    抱歉,其实内容并不如题!!!真正的题目应该为<.net core 并发下由于注入模式引起的线程安全问题> 背景(写测试demo所出现的异常,供大家学习与拍砖): .net core web ...

  2. 学习CSS3之实心圆

    CSS3是最新版本的CSS,学习后可以更好的用于工作及自己修改自己代码的各种样式. border-radius圆角方法画实心圆.相当于在长方形(正方形)上画半径为边长一半的圆弧. 效果如上图,代码如下 ...

  3. .NET(WinCE、WM)转Android开发——Xamarin和Smobiler对比

    对比 WinCE Android 行业场景 扫描分拣.车载.工控 扫描分拣.车载定位 开发语言 C++.C# Java/.NET(Smobiler) 开发环境 Visual Studio Androi ...

  4. 软件开发架构介绍||OSI七层协议之物理层、数据链路层、网络层、传输层(mac地址、ip协议、断开协议、tcp协议之三次握手四次挥手)

    一.网络编程 软件开发架构 C/S架构 C:客户端 想体验服务的时候才会去找服务端体验服务 S:服务端   24小时不间断的提供服务,即时监听,随时待命 B/S架构 B:浏览器    想体验服务的时候 ...

  5. [Linux] host dig nslookup查询域名的DNS解析

    root@VM-38-204-ubuntu:~# host baidu.com baidu.com has address 220.181.57.216 baidu.com has address 1 ...

  6. Java 在PDF 中添加超链接

    对特定元素添加超链接后,用户可以通过点击被链接的元素来激活这些链接,通常在被链接的元素下带有下划线或者以不同的颜色显示来进行区分.按照使用对象的不同,链接又可以分为:文本超链接,图像超链接,E-mai ...

  7. Java 在PDF文档中绘制图形

    本篇文档将介绍通过Java编程在PDF文档中绘制图形的方法.包括绘制矩形.椭圆形.不规则多边形.线条.弧线.曲线.扇形等等.针对方法中提供的思路,也可以自行变换图形设计思路,如菱形.梯形或者组合图形等 ...

  8. Mac OS X中开启或关闭显示隐藏文件命令

    前言:之前一直用的都是 windows 系统的电脑,刚接触 Mac ,很多功能都不熟悉,写下博客记录一下,以防以后忘记,也给后来者提供方便. 命令行方式:显示隐藏文件: defaults write ...

  9. lunix脚本进程挂掉时显示cpu和内存信息及挂掉的时间

    #!/bin/shwhile [ true ]; do #查询是否有8899正在运行的进程netstat -an|grep 8899if [ $? -ne 0 ]thennowtime=$(date ...

  10. iOS开发之Masonry框架源码解析

    Masonry是iOS在控件布局中经常使用的一个轻量级框架,Masonry让NSLayoutConstraint使用起来更为简洁.Masonry简化了NSLayoutConstraint的使用方式,让 ...