您可以使用 Vant 组件库中的'Image'组件来展示图片,并且使用'Popup'组件实现图片的放大查看功能。以下是一个示例代码:

<template>
  <div>
    <van-image
      v-for='(src, index) in images'
      :key='index'
      :src='src'
      :fit='fitMode'
      @click='showImage(index)'
    />
    <van-popup v-model='showPopup' position='center'>
      <van-image
        v-if='showPopup'
        :src='images[currentIndex]'
        :fit='fitMode'
        closeable
        @click='showPopup = false'
      />
    </van-popup>
  </div>
</template>

<script>
export default {
  data() {
    return {
      images: [
        'https://example.com/image1.jpg',
        'https://example.com/image2.jpg',
        'https://example.com/image3.jpg'
      ],
      showPopup: false,
      currentIndex: 0,
      fitMode: 'cover'
    };
  },
  methods: {
    showImage(index) {
      this.currentIndex = index;
      this.showPopup = true;
    }
  }
};
</script>

在上述代码中,我们使用了'van-image'组件展示图片,并且给每个图片添加了点击事件'@click="showImage(index)"'。点击图片时,调用'showImage'方法来显示放大的图片。

放大的图片使用了'van-popup'组件,设置'position="center"'使其居中显示。当点击放大的图片时,调用'@click="showPopup = false"'来关闭放大图片的弹窗。

您可以根据您的实际需求,调整'images'数组中的图片链接和样式参数。


原文地址: https://www.cveoy.top/t/topic/o4p2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录