Image 图片

图片组件,支持懒加载、自定义形状、加载状态等

图片组件,支持懒加载、自定义形状、加载状态等

演示

9:41

代码示例

<!-- 基础用法 -->
  <re-image class="demo-image-default" :src="imageA" width="100px" height="100px" />
  <re-image class="demo-image-custom" :src="imageB" width="80px" height="80px" />

<!-- 裁剪模式 -->
  <re-image class="demo-image-aspect-fill" :src="imageA" mode="aspectFill" width="100px" height="100px" />
  <re-image class="demo-image-aspect-fit" :src="imageA" mode="aspectFit" width="100px" height="100px" />
  <re-image class="demo-image-scale-to-fill" :src="imageA" mode="scaleToFill" width="100px" height="100px" />

<!-- 形状 -->
  <re-image class="demo-image-circle" :src="imageB" shape="circle" width="100px" height="100px" />
  <re-image class="demo-image-round" :src="imageB" shape="round" width="100px" height="100px" />
  <re-image class="demo-image-square" :src="imageB" shape="square" width="100px" height="100px" />

<!-- 懒加载 -->
  <re-image class="demo-image-lazy" :src="imageA" :lazy="true" width="100px" height="100px" />
  <re-image class="demo-image-no-lazy" :src="imageA" :lazy="false" width="100px" height="100px" />

<!-- 错误状态 -->
  <re-image class="demo-image-error" src="/static/notexist.png" width="100px" height="100px" />

<!-- 长按菜单 -->
  <re-image class="demo-image-longpress" :src="imageA" :showMenuByLongpress="true" width="100px" height="100px" />

<!-- 自定义样式 -->
  <re-image class="demo-image-custom-style" :src="imageB" width="100px" height="100px" customStyle="border: 2px solid #0052d9;" />

<!-- 不同尺寸 -->
  <re-image class="demo-image-small" :src="imageA" width="50px" height="50px" />
  <re-image class="demo-image-medium" :src="imageA" width="100px" height="100px" />
  <re-image class="demo-image-large" :src="imageA" width="150px" height="150px" />

引入

推荐使用 easycom 模式,配置后无需手动 import 即可直接使用 <re-image />。

API

Image Props

名称类型默认值描述必传
srcstring""图片地址N
modestring"aspectFill"图片裁剪、缩放模式N
lazybooleanfalse是否懒加载N
shapestring"square"图片形状N
widthstring"100%"宽度N
heightstring"100%"高度N
showMenuByLongpressbooleanfalse是否开启长按图片显示识别小程序码菜单N
customStylestring""自定义样式N

Image Events

名称参数描述
error-错误时触发
load-加载时触发
click-点击时触发

Image Slots

名称描述
default默认插槽