index.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <div style="display: flex; justify-content:center;">
  3. <button style="height: 20px"><a target="_blank" :href=File>查看</a></button>
  4. <el-upload
  5. class="upload-demo"
  6. :action="uploadImgUrl"
  7. list-type="picture-card"
  8. :on-success="handleUploadSuccess"
  9. :before-upload="handleBeforeUpload"
  10. :on-error="handleUploadError"
  11. name="file"
  12. :show-file-list="false"
  13. :headers="headers"
  14. >
  15. <!-- <img v-if="value" :src="value" class="avatar" />
  16. <i v-else class="el-icon-plus avatar-uploader-icon"></i> -->
  17. <button>上传</button>
  18. </el-upload>
  19. <button @click="Delete" style="height: 20px; margin-left:10px;">删除</button>
  20. </div>
  21. </template>
  22. <script>
  23. import { getToken } from "@/utils/auth";
  24. export default {
  25. components: {},
  26. data() {
  27. return {
  28. File: '',
  29. uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
  30. headers: {
  31. Authorization: "Bearer " + getToken(),
  32. },
  33. };
  34. },
  35. // props: {
  36. // value: {
  37. // type: String,
  38. // default: "",
  39. // },
  40. // },
  41. methods: {
  42. handleUploadSuccess(res) {
  43. console.log(res)
  44. this.$emit("input", res);
  45. // this.$emit("fileName", res.fileName);
  46. this.File = res.url;
  47. console.log(res.url)
  48. this.loading.close();
  49. },
  50. handleBeforeUpload() {
  51. this.loading = this.$loading({
  52. lock: true,
  53. text: "上传中",
  54. background: "rgba(0, 0, 0, 0.7)",
  55. });
  56. },
  57. // 删除
  58. Delete() {
  59. this.File = '';
  60. this.$message('已删除')
  61. },
  62. handleUploadError() {
  63. this.$message({
  64. type: "error",
  65. message: "上传失败",
  66. });
  67. this.loading.close();
  68. },
  69. },
  70. watch: {},
  71. };
  72. </script>
  73. <style scoped lang="scss">
  74. .avatar {
  75. width: 100%;
  76. height: 100%;
  77. }
  78. .upload-demo /deep/ .el-upload--picture-card {
  79. height: 18px;
  80. width: 45px;
  81. line-height: 18px;
  82. border: none;
  83. margin-left:10px!important;
  84. }
  85. .upload-demo {
  86. line-height: 30px;
  87. margin-left:0px!important;
  88. }
  89. </style>