最近整理了一下,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:白盒测试---细化明确任务DAY5

    收到老师给我写的评论,感觉老师真的太认真,每个博客都有仔细的,参考了老师发给我的博客,我才明白老师想要的博客内容原来是具体实际的进展记录.我们组其实这些东西早就确定了,会议也开了,但是我之前不明白博客 ...

  2. Linux 下安装Yaf扩展

    1.在官网下载了yaf扩展包 yaf-3.0.3.tgz 2.开始安装yaf扩展 tar zxvf yaf-3.0.3.tgz cd yaf-3.0.3 phpize ./configure --wi ...

  3. WCF把书读薄(4)——事务编程与可靠会话

    WCF把书读薄(3)——数据契约.消息契约与错误契约 真不愧是老A的书,例子多,而且也讲了不少原理方面的内容,不过越读越觉得压力山大……这次来稍微整理整理事务和可靠会话的内容. 十八.事务编程 WCF ...

  4. 生日蜡烛——第七届蓝桥杯C语言B组(省赛)第二题

    原创 生日蜡烛 某君从某年开始每年都举办一次生日party,并且每次都要吹熄与年龄相同根数的蜡烛. 现在算起来,他一共吹熄了236根蜡烛. 请问,他从多少岁开始过生日party的? 请填写他开始过生日 ...

  5. tornado+nginx上传视频文件

    [http://arloz.me/tornado/2014/06/27/uploadvideotornado.html] [NGINX REFRER:Nginx upload module] 由于to ...

  6. SQL cast 函数

    (1).CAST()函数的参数是一个表达式,它包括用AS关键字分隔的源值和目标数据类型.以下例子用于将文本字符串'12'转换为整型: SELECT CAST('12' AS int) (2).返回值是 ...

  7. Windows10电脑系统时间校准

    有时候新安装电脑系统,系统时间不对,需要主动去校准系统时间. 1.点击时间 2.日期和时间设置 3.其他日期.时间和区域设置 4.设置时间和日期 5.Internet 时间 6.点击立即更新,如果更新 ...

  8. Mysql的用户基本操作

    创建用户: mysql> create user 'cai'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.0 ...

  9. Django rest framework框架——APIview源码分析

    一.什么是rest REST其实是一种组织Web服务的架构,而并不是我们想象的那样是实现Web服务的一种新的技术,更没有要求一定要使用HTTP.其目标是为了创建具有良好扩展性的分布式系统. 可用一句话 ...

  10. python3入门之字符串

    获得更多资料欢迎进入我的网站或者 csdn或者博客园 经过前面的介绍相信大家也对python有了一个初步的了解:本节主要介绍字符串,不管学习什么编语言字符串一定在其中扮演着重要的地位.本节主要讲解,字 ...