|
@@ -1,8 +1,8 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
- <el-upload v-if="type === 'file' ? true : hideUpload" :action="action" :headers="headers" :data="data"
|
|
|
- :show-file-list="false" :list-type="type === 'file' ? '':'picture-card'" :before-upload="beforeUpload"
|
|
|
- :on-success="onSuccess">
|
|
|
+ <el-upload ref="upload" v-if="type === 'file' ? true : hideUpload" :action="action" :headers="headers"
|
|
|
+ :data="data" :show-file-list="false" :list-type="type === 'file' ? '':'picture-card'"
|
|
|
+ :before-upload="beforeUpload" :on-success="onSuccess" :http-request="httpRequest">
|
|
|
<el-button v-if="type === 'file'" type="primary" style="margin:0">上传文件</el-button>
|
|
|
<i v-else slot="default" class="el-icon-plus" />
|
|
|
</el-upload>
|
|
@@ -16,6 +16,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { client } from '@/api/oss'
|
|
|
import { getToken } from "@/utils/auth";
|
|
|
export default {
|
|
|
props: {
|
|
@@ -75,16 +76,29 @@ export default {
|
|
|
beforeUpload(file) {
|
|
|
this.data.multipartFile = file
|
|
|
},
|
|
|
+
|
|
|
// 上传成功
|
|
|
onSuccess(file) {
|
|
|
this.hideUpload = false
|
|
|
this.$emit('success', this.newUrl = file.data)
|
|
|
},
|
|
|
+
|
|
|
// 删除
|
|
|
handleRemove() {
|
|
|
this.hideUpload = true
|
|
|
this.$emit('delete', this.newUrl = '')
|
|
|
},
|
|
|
+
|
|
|
+ async httpRequest(e) {
|
|
|
+ try {
|
|
|
+ let file = e.file
|
|
|
+ let fileName = file.name
|
|
|
+ const res = client.put(fileName, file)
|
|
|
+ console.log(res);
|
|
|
+ } catch(err) {
|
|
|
+ console.log(err);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|