index.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <div>
  3. <el-upload
  4. ref="upload"
  5. :action="fileAction"
  6. :on-remove="handleRemove"
  7. :on-success="handleSuccess"
  8. :on-error="handleError"
  9. name="file">
  10. <el-button slot="trigger" size="mini" type="primary">选取文件</el-button>
  11. </el-upload>
  12. </div>
  13. </template>
  14. <script>
  15. import {uploadFileUrl, deleteFile} from "@/api/file/file";
  16. export default {
  17. name: "index",
  18. data() {
  19. return {
  20. fileAction: ''
  21. }
  22. },
  23. created() {
  24. this.fileAction = uploadFileUrl()
  25. },
  26. methods: {
  27. handleRemove(file, fileList) {
  28. let url = file.response.data.url;
  29. deleteFile(url).then(res => {
  30. this.$message({
  31. message: '操作成功!',
  32. type: 'success'
  33. });
  34. });
  35. this.$emit('removeFile', url)
  36. },
  37. handleSuccess(response, file, fileList) {
  38. let fileUrl = response.data.url
  39. this.$emit('getFileUrl', fileUrl)
  40. },
  41. handleError() {
  42. this.$message({
  43. message: '上传失败,请稍候再试!',
  44. type: 'warning'
  45. });
  46. },
  47. }
  48. }
  49. </script>
  50. <style scoped>
  51. </style>