最近整理了一下,table表格的编辑状态,把一般表格里需要输入的类型都放进来了,实现的功能如图
 
 
这里面的input输入框没什么好说的,绑定对应的值就可以,要注意的是组件上传的upload,这个表格是有多个upload上传组件的,upload组件的文件列表是根据fileList展示的,所在在处理方法的时候要注意fileList的处理
 
下面放代码
<template>
<div>
<p>shopInfo</p>
<div class="company">
<p><el-button type="primary" @click="addCompany">添加公司</el-button></p>
<el-table
ref="multipleTable"
:data="tableData3"
border
style="width: 100%">
<el-table-column
label="序号"
type="index"
width="55">
</el-table-column>
<el-table-column
label="公司名称"
show-overflow-tooltip>
<template slot-scope="scope">
<el-input v-model="scope.row.name" placeholder="请输入公司名称"></el-input>
</template>
</el-table-column>
<el-table-column
label="注册时间"
show-overflow-tooltip>
<template slot-scope="scope">
<el-date-picker
v-model="scope.row.date"
type="date"
placeholder="选择日期">
</el-date-picker>
</template>
</el-table-column>
<el-table-column
label="注册资金"
show-overflow-tooltip>
<template slot-scope="scope">
<el-input @blur="InputNumber(scope.row, 'amount')" v-model="scope.row.amount" placeholder="请输入注册资金"></el-input>
</template>
</el-table-column>
<el-table-column
label="注册文件"
show-overflow-tooltip>
<template slot-scope="scope">
<el-upload
class="upload-demo"
:action="action"
:data="uploadData"
:on-preview="handlePreview"
<!-- 在组件的回调函数里加一个索引的参数 -->
:on-remove="function(file,fileList){return handleRemove(file,fileList,scope.$index)}"
:on-success="function(res,file,fileList){return handleSuccess(res,file,fileList,scope.$index)}"
multiple
:limit="1"
:file-list="fileList[scope.$index]">
<el-button size="small" type="text" v-if="!scope.row.file">上传文件</el-button>
</el-upload>
<span class="delete" @click="deleteCompany(scope.$index)"><img src="/static/images/close.png" alt=""></span>
</template>
</el-table-column>
</el-table>
</div>
</div>
</template>
<style scoped>
.company {
padding: 30px;
text-align: left;
}
.delete {
position: absolute;
top: 25px;
right: 10px;
}
td .el-upload-list__item {
margin-top: -25px;
}
</style>
<script>
// import host from 'rootPath/config/host' // host文件
// import apiPath from 'rootPath/config/api.json' // api文件 export default {
name: 'shopInfo', data () {
return {
tableData3: [],
selectedTable: [],
fileList: [[]],
// action: `${host.apiUrl}${apiPath.common.qiniuupload}`,
action: ``,
uploadData: {userId: 1304, pathName: 'company'}
}
}, created () {
this.setTable()
}, methods: {
setTable () {
this.tableData3 = [{
name: '',
date: '',
amount: null,
file: ''
}]
}, // 添加公司
addCompany () {
this.tableData3.push({
name: '',
date: '',
amount: null,
file: ''
})
this.fileList.push([])
}, // 删除公司
deleteCompany (i) {
this.tableData3.splice(i, 1)
// 删除的时候要把fileList清除,否则页面已上传的文件不会被清空
this.fileList.splice(i, 1)
console.log(this.fileList)
}, // 过滤输入的金额
InputNumber (row, property) {
row[property] = this.limitInputPointNumber(row[property])
}, // 限制只能输入数字(可以输入两位小数)
limitInputPointNumber (val) {
if (val === 0 || val === '0' || val === '') {
return ''
} else {
let value = null
value = String(val).replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
value = value.replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
value = value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
value = value.replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数
return value
}
}, // 预览图片
handlePreview (file) { }, // 删除图片
handleRemove (file, fileList, index) {
this.tableData3[index].file = ''
}, // 图片上传
handleSuccess (res, file, fileList, index) {
if (res.code) {
this.tableData3[index].file = res.data.url
}
// 上传之后,把返回的fileList赋值给对应组件的fileList
this.fileList[index] = fileList
}
}
}
</script>

可编辑的el-table表格,结合input输入,upload文件上传的表格的更多相关文章

  1. 动态input file多文件上传到后台没反应的解决方法!!!

    其实我也不太清除具体是什么原因,但是后面就可以了!!! 我用的是springMVC 自带的文件上传 1.首先肯定是要有springMVC上传文件的相关配置! 2.前端 这是动态input file上传 ...

  2. javascript input type=file 文件上传

    在JS中,input type=file 是常用的文件上传API,但感觉W3C说的不是很清楚,同时网上的资料也比较乱. 由于做微信开发,所以网页打算尽量少用第三方库或者插件,以加快网页的加载速度.因为 ...

  3. js 实现 input type="file" 文件上传示例代码

    在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...

  4. input type='file'文件上传自定义样式

    使用场景: 在未使用UI库时免不了会用到各种上传文件,那么默认的上传文件样式无法达到项目的要求,因此重写(修改)上传文件样式是必然的,下面的效果是最近项目中自己写的一个效果,写出来做个记录方便以后使用 ...

  5. [置顶] js 实现 <input type="file" /> 文件上传

    在开发中,文件上传必不可少,<input type="file" /> 是常用的上传标签,但是它长得又丑.浏览的字样不能换,我们一般会用让,<input type ...

  6. jspsmartupload 文件上传让input数据和文件上传同时提交

    一.使用原因: 文件上传时,表单的属性中必须要有multipart/form-data,如以下例子: <form name="form_post" class="a ...

  7. input type="file"文件上传时得到文件的本地路劲

    <!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta name=& ...

  8. input type="file"文件上传到后台读取

    html页面(表单采用bootStrap) js部分: //更换头像时把上传的图片post方式到控制器 <script type="text/javascript"> ...

  9. input框多文件上传

    在input标签中加入 multiple 属性,可以在一个输入框中选择多个文件进行上传 <input type="file" name="img" mul ...

随机推荐

  1. 实践作业3:接到任务及思考DAY1

    今天,老师又布置了新的学习任务,关于白盒测试.感觉黑盒测试,我们用的比较多,白盒测试就相对陌生了.上课的时候老师虽然也进行了一定的点拨,外加我们学习了SPOC视频,但是并没有看到什么具体的项目,所以实 ...

  2. [redis]redis-cluster搭建

    1.概述: redis是一种工作在内存里no-sql的非关系型数据库,广泛应用于缓存需求,以减少大量的数据访问对数据库的压力,还很适合用来充当整个互联网架构中各级之间的cache 比如lvs的4层转发 ...

  3. 关于在datepicker中,只选年月

    有这么个需求,datepicker默认是选某个具体的日子的,但是现在只选到年月为止, solution: html如下: <div> <label for="startDa ...

  4. javaScript入门之常用事件

    JS中的常用事件 onfocus/onblur:聚焦离焦事件,用于表单校验的时候比较合适. onclick/ondblclick:鼠标单击和双击事件 onkeydown/onkeypress:搜索引擎 ...

  5. 【转】Android android listview的HeadView左右切换图片(仿新浪,网易,百度等切换图片)

    首先我们还是看一些示例:(网易,新浪,百度)      下面我简单的介绍下实现方法:其实就是listview addHeaderView.只不过这个view是一个可以切换图片的view,至于这个vie ...

  6. CRC-32 校验算法

      crc32的头文件 ===========================分割线=========================== //crc32.h #ifndef _CRC32_H #de ...

  7. C#生成静态文件

    一般生成文件都是通过读取模板文件,然后替换标签. 这些古老的方法使用起来不但麻烦而且效率还不怎么样. 这里给添加介绍一个方法. 如果你用过asp.net.mvc (Razor),你就应该明白 chtm ...

  8. vs2010远程调试断点无效问题

    ps:本人按照下面的方式设置成功,个人感觉写的也比较清楚 来源:http://www.cnblogs.com/OpenCoder/archive/2010/02/17/1668983.html   v ...

  9. struts2配置文件的解释

    1 <?xml version="1.0" encoding="GB2312"?>  <!DOCTYPE struts PUBLIC &quo ...

  10. 【转】远程桌面关闭后TeamViewer不能连接

    源地址:http://www.cnblogs.com/qk2014/p/9274852.html 1.本地安装TeamViewer,完成后如下: 2.远程服务器也安装TeamViewer 在本地Tea ...