uploadImg.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="">
  3. <view style="position: relative;" class="uploadImg" @click="chooseImage">
  4. <view v-if="!model">
  5. <image style="width: 60rpx;height: 60rpx;margin-bottom: 20rpx;" :src="addImg"></image>
  6. <text>{{title}}</text>
  7. </view>
  8. <image class="img" v-else :src="model"></image>
  9. <image v-if="!model && enableImg" style="height: 160rpx;width: 90%;position: absolute" :src="bgImg">
  10. </image>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. title:String,
  18. //图标
  19. addImg: {
  20. type: String,
  21. default: 'https://guosen-bucket-ldt.obs.cn-south-1.myhuaweicloud.com:443/723e0e52706a46159203f2d243873485-t5yIWXtGE8l04314394a1700881f3d4c73f10db523dd.png'
  22. },
  23. //是否开启背景图片
  24. enableImg: Boolean,
  25. //背景图片
  26. bgImg: {
  27. type: String,
  28. default: 'https://guosen-bucket-ldt.obs.cn-south-1.myhuaweicloud.com:443/704abb0fbe654e95ae1f57a458dc5f92-FPFbZdIYvEv4be3706cc937d3313d3674ac283ae53fe.png'
  29. },
  30. dataName: String,
  31. model:String
  32. },
  33. data() {
  34. return {
  35. };
  36. },
  37. onLoad() {
  38. },
  39. methods: {
  40. chooseImage() {
  41. this.$emit('click', this.dataName)
  42. }
  43. }
  44. };
  45. </script>
  46. <style lang="scss" scoped>
  47. .uploadImg {
  48. display: flex;
  49. align-items: center;
  50. justify-content: center;
  51. margin: 20rpx;
  52. view {
  53. z-index: 10;
  54. border: 4rpx dashed #e1e1e1;
  55. width: 480rpx;
  56. height: 300rpx;
  57. border-radius: 10rpx;
  58. display: flex;
  59. justify-content: center;
  60. align-items: center;
  61. flex-direction: column;
  62. }
  63. .icon {
  64. width: 70rpx;
  65. height: 70rpx;
  66. }
  67. .img {
  68. width: 480rpx;
  69. height: 300rpx;
  70. }
  71. text {
  72. color: #999;
  73. }
  74. }
  75. </style>