Skip to content
On this page

图片预览

图片放大预览

基础用法

示例代码

vue
<template>
  <button @click="show = true">图片预览</button>
  <YikViewImage v-model:show="show" :imgs="imgs" :index="1"></YikViewImage>
</template>
<script setup>
import { reactive, toRefs } from "vue";
const state = reactive({
  show: false,
  imgs: [
    "https://img0.baidu.com/it/u=1604010673,2427861166&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=889",
    "https://img1.baidu.com/it/u=1458656822,2078909008&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=750",
  ],
});
const { show, imgs } = toRefs(state);
</script>
<style lang="less" scoped>
button {
  padding: 5px 10px;
  background-color: #1a89fa;
  font-size: 14px;
  color: #fff;
  border-radius: 5px;
  margin-right: 10px;
  margin-bottom: 10px;
}
</style>

属性

属性名说明类型默认值
v-model:show是否展示图片预览booleanfalse
isClickMask是否点击遮罩层关闭booleantrue
isAutoSize超过视口自动缩放图片大小booleantrue
pct自定义缩放比例图片大小(当 isAutoSize 为 false 时,生效。)Number100
imgs图片组Array[]
index默认打开第几张图片(数组的下标)Number0