upImg.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <u-upload :max-count="maxCount" :action="requertUrl" :header="header" :auto-upload="autoUpload" @on-uploaded="getImg"></u-upload>
  3. <!-- <u-upload max-count="1" :action="upUrl" :header="upHeader" ref="uUpload" @on-uploaded="setImg"></u-upload> -->
  4. </template>
  5. <script>
  6. import { mapState } from 'vuex';
  7. export default {
  8. props: {
  9. // 是否自动上传
  10. autoUpload: {
  11. type: Boolean,
  12. default: true
  13. },
  14. // 最大上传数量
  15. maxCount: {
  16. type: Number | String,
  17. default: 1
  18. },
  19. // 请求地址
  20. action: {
  21. default: ''
  22. },
  23. // 请求头
  24. header: {
  25. type: Object,
  26. default: function() {
  27. return {
  28. 'Authori-zation': 'Bearer ' + uni.getStorageSync('token') || ''
  29. };
  30. }
  31. }
  32. },
  33. data() {
  34. return {
  35. refName:''
  36. };
  37. },
  38. computed: {
  39. ...mapState(['baseURL']),
  40. // 默认请求地址
  41. requertUrl() {
  42. if (!this.action) {
  43. return this.baseURL + '/api/upload/image';
  44. } else {
  45. return this.action;
  46. }
  47. },
  48. getImg(e) {
  49. console.log(e);
  50. // this.$emit('on-uploaded', e);
  51. },
  52. // 手动上传
  53. upload(){
  54. this.$refs.upLoad.upload()
  55. }
  56. },
  57. created() {
  58. console.log(this);
  59. },
  60. methods: {}
  61. };
  62. </script>
  63. <style></style>