previewImage.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view class="container">
  3. <swiper v-if="list.length" class="swiper" :indicator-dots="list.length > 1" :circular="true" indicator-color="#999"
  4. indicator-active-color="#fff">
  5. <swiper-item v-for="(item, index) in list" @click="preview(index)" :key="item.url">
  6. <image class="image" :src="item.url" mode="aspectFit" lazy-load="true" />
  7. </swiper-item>
  8. </swiper>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: "prodnum-06",
  14. props: {
  15. attinfos: Array
  16. },
  17. data() {
  18. return {
  19. list: []
  20. }
  21. },
  22. watch: {
  23. attinfos: function (newVal) {
  24. this.list = newVal.filter(v => v.usetype == "previewImage")
  25. }
  26. },
  27. methods: {
  28. preview(index) {
  29. console.log(index)
  30. uni.previewImage({
  31. current: index,
  32. urls: this.list.map(v => v.url),
  33. indicator: "number",
  34. loop: true,
  35. longPressActions: {
  36. itemList: ['发送给朋友', '保存图片', '收藏'],
  37. success: function (data) {
  38. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  39. },
  40. fail: function (err) {
  41. console.log(err.errMsg);
  42. }
  43. }
  44. });
  45. }
  46. },
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .container {
  51. .swiper {
  52. width: 355px;
  53. height: 158px;
  54. margin: 15px auto 0;
  55. .image {
  56. width: 355px;
  57. height: 158px;
  58. }
  59. }
  60. }
  61. </style>