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. [Android]自己动手做个拼图游戏

    目标 在做这个游戏之前,我们先定一些小目标列出来,一个一个的解决,这样,一个小游戏就不知不觉的完成啦.我们的目标如下: 游戏全屏,将图片拉伸成屏幕大小,并将其切成若干块. 将拼图块随机打乱,并保证其能 ...

  2. 【转载】Docker+Kubernetes 干货文章精选

    主要涉及到以下关键字: K8S.Docker.微服务.安装.教程.网络.日志.存储.安全.工具.CI/CD.分布式.实践.架构等: 以下盘点2018年一些精选优质文章! 漫画形式: 漫画:小黄人学 S ...

  3. Java8新特性之一:Lambda表达式

    Java8是自java5之后最重大的一次更新,它给JAVA语言带来了很多新的特性(包括编译器.类库.工具类.JVM等),其中最重要的升级是它给我们带来了Lambda表达式和Stream API. 1. ...

  4. Git版本控制 —— IDE工具(IDEA)

    本文介绍使用IDEA控制Git操作 关联本地Git客户端 首先要根据系统环境安装Git客户端 然后使用File --> Settings -->  Version Control --&g ...

  5. 面试前必须知道的MySQL命令【explain】

    前言 只有光头才能变强 刷面试题的时候,不知道你们有没有见过MySQL这两个命令:explain和profile(反正我就见过了).. 之前虽然知道这两个命令大概什么意思,但一直没有去做笔记.今天发现 ...

  6. 深入理解令牌认证机制(token)

    以前的开发模式是以MVC为主,但是随着互联网行业快速的发展逐渐的演变成了前后端分离,若项目中需要做登录的话,那么token成为前后端唯一的一个凭证. token即标志.记号的意思,在IT领域也叫作令牌 ...

  7. 关于ORACLE的各种操作~持续汇总~

    增.删.改: 增加所有 INSERT INTO 表名 VALUES(序列名.NEXTVAL,'值1','值2','值3','值4','值5'); 指定增加 INSERT INTO 表名(字段1,字段2 ...

  8. 积极参与开源项目,促进.NET Core生态社区发展

    今天早上在微信群里聊天聊到百度的SDK 已经支持.NET Core, 百度已经在3月份就支持了,想起当时还是我在他们的github上提的issue: https://github.com/Baidu- ...

  9. Fusion Log

    What is Fusion Log? Also known as the Fusion Log or Assembly Binding Log Viewer. This tool is instal ...

  10. PHP全栈学习笔记15

    PHP标记风格 PHP一共支持4种标记风格 <?php echo "这是XML风格的标记"; ?> 脚本风格 <script language="php ...