更新记录

1.0.0(2026-04-29) 下载此版本

初始发布


平台兼容性

uni-app(5.0)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
- - -
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - - -

sq-img-preview 图片预览组件

一个功能完善的图片预览组件,支持本地和网络图片预览,提供丰富的交互功能。

功能特性

  • 🖼️ 支持本地和网络图片预览
  • 🔄 双指缩放
  • 👆 左右滑动切换图片
  • 💾 图片保存功能
  • ⚙️ 可自定义功能按钮

使用方法

1. 引入并注册组件

// 在页面的 script 中引入并注册
import SqImgPreview from "@/uni_modules/sq-img-preview/components/sq-img-preview/sq-img-preview.vue";

export default {
  components: {
    SqImgPreview,
  },
};

2. 在模板中使用

<template>
  <view>
    <!-- 你的内容 -->
    <sq-img-preview ref="imagePreview"></sq-img-preview>
  </view>
</template>

3. 调用预览方法

通过 ref 调用组件的 show 方法:

// 调用示例
this.$refs.imagePreview.show(imglist, index, options);

API 参数说明

show(imglist, index, options)

参数 类型 必填 说明
imglist Array 图片列表,支持本地路径或网络地址
index Number 默认显示第几张图片(从 0 开始),默认为 0
options Object 配置项,可自定义功能按钮

options 配置

可以自定义配置底部功能按钮:

{
  buttons: [
    {
      text: "保存到相册",
      type: "save",
      handler: () => {
        // 自定义处理逻辑
      },
    },
  ];
}

完整示例

<template>
  <view>
    <view class="image-list">
      <image v-for="(img, index) in images" :key="index" :src="img" @click="previewImage(index)" />
    </view>

    <sq-img-preview ref="imagePreview"></sq-img-preview>
  </view>
</template>

<script>
export default {
  data() {
    return {
      images: ["https://example.com/image1.jpg", "https://example.com/image2.jpg", "https://example.com/image3.jpg"],
    };
  },
  methods: {
    previewImage(index) {
      this.$refs.imagePreview.show(this.images, index, {
        buttons: [
          {
            text: "保存到相册",
            type: "save",
          },
          {
            text: "分享",
            type: "share",
            handler: () => {
              // 自定义分享逻辑
              console.log("分享图片");
            },
          },
        ],
      });
    },
  },
};
</script>

注意事项

  • 确保图片路径正确,支持本地路径和网络 URL
  • 网络图片需要配置域名白名单(如在 manifest.json 中配置)
  • 保存功能需要相应的权限(如相册访问权限)

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

1、本插件可免费下载使用;

2、未经许可,严禁复制本插件派生同类插件上传插件市场;

3、未经许可,严禁在插件市场恶意复制抄袭本插件进行违规获利;

4、对本软件的任何使用都必须遵守这些条款,违反这些条款的个人或组织将面临法律追究。

暂无用户评论。