頁面:
<el-upload action="上傳接口url地址" :http-request="uploadSectionFile" multiple accept=".xls,.xlsx" :limit="1" :show-file-list="false"
ref="upload">
<el-button type="primary">上傳<i class="el-icon-upload el-icon--right"></i></el-button>
</el-upload>
vue:
uploadSectionFile(param){
const self = this;
//file就是當前添加的文件
var fileObj = param.file;
// FormData 對象
var form = new FormData();
// 文件對象,key是後臺接受的參數名稱
form.append("file", fileObj);
self.$http.post("上傳url接口地址",form).then((res) => {
// 這裏做上傳後的操作
console.log(res);
if (res) {
//todo 頁面提示信息
}
});
},
遇到的問題:
1.本以爲重新後,不再需要action了,但是去掉action後,報錯;
2.加上action後,認爲不需要在重寫的請求中,再次輸入action了,發現前端不報錯了,上傳不成功,無奈,又加上了,
3.action可以不傳入任何東西,但是這個節點需要存在,比如:action="",測試後,發現頁面寫爲action="",也是可以上傳成功的
版本:elementUI:2.13.0
vue:2.0
原因:暫時未知