Skip to content

Image 图片

介绍

为原生图片封装了一些有用的属性,如加载状态、失败状态、圆角等功能。

导入

js
import Image from '@/components/basic/Image.vue'

用法

基础用法

基础用法与原生 Image 标签一致,增加了 width、height 宽高属性。

vue
<template>
  <Image 
    src="https://imengyu.top/assets/images/test/1.jpg"
    width="200rpx" 
    height="200rpx" 
  />
</template>

圆形图片

通过 round 属性可以设置图片变圆,radius 可以指定圆角大小。

vue
<template>
  <view style="display: flex; gap: 10px;">
    <Image 
      src="https://imengyu.top/assets/images/test/2.jpg"
      width="200rpx" 
      height="200rpx" 
      round
    />
    <Image 
      src="https://imengyu.top/assets/images/test/3.jpg"
      width="200rpx" 
      height="200rpx"
      round
      radius="20rpx"
    />
  </view>
</template>

加载中

通过 showLoading 属性来显示加载中提示,默认是 true。

vue
<template>
  <Image 
    src="https://imengyu.top/assets/images/test/3.jpg"
    width="200rpx" 
    height="200rpx"
    round 
    showLoading
    radius="10"
  />
</template>

加载失败

通过 showFailed 属性来显示加载失败提示,默认是 true。

vue
<template>
  <Image
    src="https://imengyu.top/assets/images/test2/2.jpg"
    width="200rpx" 
    height="200rpx"
    round 
    radius="10"
  />
</template>

点击预览

通过 clickPreview 属性可以点击预览图片。

vue
<template>
  <Image
    src="https://imengyu.top/assets/images/test/1.jpg"
    width="200rpx" 
    height="200rpx"
    clickPreview
  />
</template>

自定义加载状态样式

可以自定义加载中圆圈的颜色和大小。

vue
<template>
  <Image
    src="https://imengyu.top/assets/images/test/1.jpg"
    width="200rpx" 
    height="200rpx"
    showLoading
    loadingColor="primary"
    loadingSize="30"
  />
</template>

API 参考

Image

图片组件。

Props

名称说明类型必填默认值
src图片地址string-''
failedImage加载失败图片地址string-''
defaultImage为空时图片地址string-''
showLoading是否显示加载中提示,默认是boolean-true
showFailed是否显示加载失败提示,默认是boolean-true
showGrey是否显示灰色占位,默认是boolean-false
width图片宽度string | number--
height图片高度string | number--
clickPreview是否可以点击预览图片boolean-false
loading初始加载中状态boolean-false
loadingColor加载中圆圈颜色string-border.default
loadingSize加载中圆圈大小string | number-50
touchable指定图片是否可以点击,默认否boolean-false
round图片是否有圆角boolean-false
radius当round为true的圆角大小,默认是50%string | number-50%
innerStyle内部样式object--
mode图片裁剪、缩放的模式,同原生image组件string--
lazyLoad是否懒加载boolean--
fadeShow图片显示动画效果boolean--
webp是否支持webp格式boolean--
showMenuByLongpress是否开启长按图片显示菜单boolean--
draggable是否可拖拽boolean--

Events

名称说明参数
click点击事件$event

主题变量

名称类型默认值说明
ImageShowGreybooleanfalse是否显示灰色占位
ImageLoadingColorstringborder.default加载中圆圈颜色
ImageLoadingSizenumber50加载中圆圈大小
ImageRoundbooleanfalse图片是否有圆角
ImageRadiusstring50%当round为true的圆角大小