avatar-upload.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div class="components-container">
  3. <aside>This is based on
  4. <a class="link-type" href="//github.com/dai-siki/vue-image-crop-upload"> vue-image-crop-upload</a>.
  5. {{ $t('components.imageUploadTips') }}
  6. </aside>
  7. <pan-thumb :image="image" />
  8. <el-button type="primary" icon="el-icon-upload" style="position: absolute;bottom: 15px;margin-left: 40px;" @click="imagecropperShow=true">
  9. Change Avatar
  10. </el-button>
  11. <image-cropper
  12. v-show="imagecropperShow"
  13. :key="imagecropperKey"
  14. :width="300"
  15. :height="300"
  16. url="https://httpbin.org/post"
  17. lang-type="en"
  18. @close="close"
  19. @crop-upload-success="cropSuccess"
  20. />
  21. </div>
  22. </template>
  23. <script>
  24. import ImageCropper from '@/components/ImageCropper'
  25. import PanThumb from '@/components/PanThumb'
  26. export default {
  27. name: 'AvatarUploadDemo',
  28. components: { ImageCropper, PanThumb },
  29. data() {
  30. return {
  31. imagecropperShow: false,
  32. imagecropperKey: 0,
  33. image: 'https://wpimg.wallstcn.com/577965b9-bb9e-4e02-9f0c-095b41417191'
  34. }
  35. },
  36. methods: {
  37. cropSuccess(resData) {
  38. this.imagecropperShow = false
  39. this.imagecropperKey = this.imagecropperKey + 1
  40. this.image = resData.files.avatar
  41. },
  42. close() {
  43. this.imagecropperShow = false
  44. }
  45. }
  46. }
  47. </script>
  48. <style scoped>
  49. .avatar{
  50. width: 200px;
  51. height: 200px;
  52. border-radius: 50%;
  53. }
  54. </style>