vue+elementui el-upload上传文件携带参数
标签:fun net http amp margin tps port nod head
upload
ref="upload"
style="display:inline;margin-left:10px;"
action="url"
:auto-upload="false"
:multiple="false"
:show-file-list="false"
:before-upload="beforeUpload"
:on-change="changeFile"
accept=".xlsx,.xls"
:file-list="fileList">
export function parsingExcelAddData (data, setId) {
return fetch({
url: ‘‘,
method: ‘post‘, // 方式一定是post
headers: {
‘Content-Type‘: ‘multipart/form-data‘,
‘setId‘: setId //放到formData里后端拿不到,所以放到请求头里了
},
data: data // 参数需要是单一的formData形式
})
}
beforeUpload(file) {
let filename = file.name
let arr = filename.split(‘.‘)
if (arr[1] !== ‘xls‘ && arr[1] !== ‘xlsx‘) {
this.$message.error(‘上传文件只能是 excel/xls 格式!‘)
return false
}
return arr
},
changeFile(file,fileList) {
let fd = new FormData();
fd.append(‘file‘,file.raw);//传文件
let self = this
parsingExcelAddData(fd,this.dataObj.setId).then(function(res){
if (res.data.success) {
self.$message({
type: ‘success‘,
message: ‘上传成功‘
})
self.currentNodeData(self.dataObj.setId) //此方法是重新刷数据,可以自己写
} else {
self.$message({
type: ‘warning‘,
message: res.data.msg
})
return false
}
})
}
原文链接:https://blog.csdn.net/weixin_43173924/article/details/89395537
vue+elementui el-upload上传文件携带参数
标签:fun net http amp margin tps port nod head
原文地址:https://www.cnblogs.com/smile-fanyin/p/12431591.html
评论