index.vue 754 B

123456789101112131415161718192021222324252627282930313233
  1. <template>
  2. <el-upload ref="upload" :action="actionApi" :auto-upload="auto" :headers="{ authorization: token }" v-bind="$attrs">
  3. <template v-for="(index, name) in $slots" v-slot:[name]>
  4. <slot :name="name"></slot>
  5. </template>
  6. </el-upload>
  7. </template>
  8. <script setup lang="ts">
  9. import { ref } from 'vue'
  10. import { env } from '/admin/support/helper'
  11. import { getAuthToken } from '/admin/support/helper'
  12. const props = defineProps({
  13. action: {
  14. type: String,
  15. default: 'upload',
  16. },
  17. auto: {
  18. type: Boolean,
  19. default: true,
  20. },
  21. })
  22. const baseURL = env('VITE_BASE_URL')
  23. const actionApi = ref<string>('')
  24. actionApi.value = baseURL + props.action
  25. const token = ref<string>()
  26. token.value = 'Bearer ' + getAuthToken()
  27. </script>