deleteUploadImg1.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div >
  3. <van-row gutter="10" >
  4. <van-col span="6" v-for="(urls, index) in imgs" :key="index">
  5. <div class="imgview">
  6. <van-icon name="close" size="16" v-on:click="deleteImg(index,urls.id)"/>
  7. <img v-if="urls.type=='2'" :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)"/>
  8. <img v-else :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)"/>
  9. </div>
  10. </van-col>
  11. </van-row>
  12. <!-- <div style="padding: 10px 16px 0;">-->
  13. <!-- <div class="img-box" v-for="(urls, index) in imgs" :key="index">-->
  14. <!-- <van-icon name="clear" v-on:click="deleteImg(index,urls.id)"/>-->
  15. <!-- <img v-if="urls.type=='2'" :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)"/>-->
  16. <!-- <img v-else :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)"/>-->
  17. <!-- </div>-->
  18. <!-- </div>-->
  19. </div>
  20. </template>
  21. <script>
  22. import {ImagePreview} from "vant";
  23. import {removePhoto} from "@/api/index";
  24. export default {
  25. name: 'deleteUploadImg',
  26. props: {
  27. imgs: {
  28. type: Array,
  29. default() {
  30. return []
  31. }
  32. },
  33. },
  34. data() {
  35. return {
  36. url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API
  37. }
  38. },
  39. methods: {
  40. deleteImg(index, collectionItemId) {
  41. removePhoto({fileId: collectionItemId}).then(res => {
  42. if (res.code == 200) {
  43. this.$toast("删除成功!")
  44. this.imgs.splice(index, 1);
  45. } else {
  46. this.$toast("删除失败!")
  47. }
  48. })
  49. },
  50. previewsImg(index) {
  51. var arrimg = []
  52. for (var imgi = 0; imgi < this.imgs.length; imgi++) {
  53. arrimg.push(this.imgs[imgi].fileUrl)
  54. }
  55. ImagePreview({
  56. images: arrimg,
  57. startPosition: index,
  58. onClose() {
  59. // do something
  60. }
  61. });
  62. },
  63. },
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .imgview {
  68. width: 100%;
  69. height: 72px;
  70. position: relative;
  71. display: inline-block;
  72. i {
  73. position: absolute;
  74. right: -2px;
  75. top: -3px;
  76. color: white;
  77. background: red;
  78. overflow: hidden;
  79. border-radius: 50%;
  80. }
  81. img {
  82. width: 100%;
  83. height: 100%;
  84. }
  85. }
  86. </style>