elementUI 阿里云oss 上传文件纯前端
<el-form-item label="选择文件" prop="imgUrl" style="height: 130px">
<el-upload
class="upload-demo"
ref="upload"
:on-exceed="onExceed"
:on-change="onChange"
:file-list="fileList"
:http-request="submit"
:before-upload="beforeUpload"
:auto-upload="false"
:limit="1"
>
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
</el-upload>
</el-form-item>
submitUpload() {
this.$refs.upload.submit();
},
onExceed() {
this.$message.error('一次只能上传一个文件');
},
beforeUpload() {
return true;
},
onChange(a, fileList) {
this.fileList = fileList;
},
submit(file) {
let apkName = new Date().getTime();
upload(`apk/alpha/${apkName}.apk`, file.file).then(res => {
this.apk.url = res.url
if (this.apk.url !== "") {
if (this.formTitle === 0) {
this.saveApk(this.apk)
} else {
this.updateApk(this.apk)
}
}
});
},