您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

propertyImage.vue 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div>
  3. <div>
  4. <label class="btn btn-b-n" style="width: 85px; height:40px;">
  5. Upload
  6. <input
  7. type="file"
  8. value="Upload Photo"
  9. style="width: 0px;height: 0px;overflow: hidden;"
  10. name="images[]"
  11. @change="imagesAdd"
  12. multiple
  13. />
  14. </label>
  15. </div>
  16. <br />
  17. <div class="form-group row">
  18. <div v-for="(img, i) in image" class="col-md-2" :key="i">
  19. <img :src="img" style="height:200px; width:150px; object-fit: cover;" />
  20. <br />
  21. <a class="fa fa-times del" @click="removeImage(key)" />
  22. </div>
  23. <br />
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. loadedImages: Function,
  31. },
  32. data() {
  33. return {
  34. images: {},
  35. image: [],
  36. };
  37. },
  38. methods: {
  39. imagesAdd(e) {
  40. const files = e.target.files || e.dataTransfer.files;
  41. this.images = [];
  42. Array.prototype.push.apply(this.images, files);
  43. if (!this.images.length) return;
  44. this.createImage(this.images);
  45. this.loadedImages(this.image);
  46. },
  47. createImage(file) {
  48. for (let i = 0; i < file.length; i++) {
  49. const reader = new FileReader();
  50. var vm = this;
  51. reader.onload = (e) => {
  52. vm.image.push(e.target.result);
  53. console.log(vm.image);
  54. };
  55. reader.readAsDataURL(file[i]);
  56. }
  57. },
  58. removeImage(key) {
  59. this.image.splice(key, 1);
  60. this.images.splice(key, 1);
  61. if (!this.image.length) {
  62. this.$refs.im.value = '';
  63. }
  64. },
  65. },
  66. };
  67. </script>