Skip to content
# t-image

Image 图片

t-image 组件介绍 ​

t-image 是 image 组件的加强版,在原有功能增加加载中、加载失败提示、圆角值和形状等。提供更完善的图片展示体验。

t-image 平台兼容 ​

HarmonyH5AndroidiOS小程序UTS
✅✅✅✅✅✅

t-image 基础用法 ​

基础用法参考 demo/image/image.uvue,通过 src 属性设置图片地址。

vue
<template>
	<view class="p-15">
		<t-section class="mb-15" title="基础功能"></t-section>
		<t-image src="/static/image/D1.jpg" :class="[`h-175 w-100% mb-15 trm`]" :fade-show="true"></t-image>
		<t-section class="mb-15" title="开启预览"></t-section>
		<t-image src="/static/image/D2.jpg" :class="[`h-175 w-100% mb-15 trm`]" :preview="true"></t-image>
		<t-section class="mb-15" title="错误占位图"></t-section>
		<t-image class="twh-175 trm" src="https://ll-yundie-xyz/pagesA/static/loginbg1.jpeg" loading="loading">
			<template #error>
				<image class="w-100%" mode="widthFix" src="/static/tabbar/dark/my.png"></image>
			</template>
		</t-image>
		<t-section class="mb-15" title="自定义加载" loading="loading"></t-section>
		<t-image class="twh-175 trm" src="https://ll-yundie-xyz/pagesA/static/loginbg1.jpeg">
			<template #loading>
				<text :class="[`ttc-i`]">加载中</text>
			</template>
			<template #error>
				<text>加载失败了</text>
			</template>
		</t-image>
		<view class="fais">
			<t-image src="/static/image/D1.jpg" class="w-150 r-10 mb-15" mode="widthFix" :fade-show="true"></t-image>
			<t-image src="/static/image/D1.jpg" class="h-150 mb-75" image-class="r-20" mode="heightFix"
				:fade-show="true"></t-image>
		</view>
	</view>
</template>
<script setup>
</script>

t-image Props ​

属性名说明类型默认值
path点击组件后跳转的页面路径;为空时仅响应事件string''
hover是否启用点击效果booleantrue
type组件主题类型,可选 info、primary、error、warning、successstring''
disabled是否禁用booleanfalse
effect组件显示主题,可选 normal、dark、light、plainstring'normal'
size组件尺寸,可选 large、medium、small、ministring'medium'
src图片资源地址string''
mode图片裁剪、缩放的模式string'scaleToFill'
placeholder加载失败时的占位文字booleanfalse
preview是否支持预览booleanfalse
fadeShow图片加载是否显示淡入动画效果booleantrue
loading加载时的文字string''
imageClassimage 样式,对应外部类 image-classstring''
loadingClassloading 文字样式,对应外部类 loading-classstring''
placeholderClassplaceholder 文字样式,对应外部类 placeholder-classstring''

mode 可选值 ​

值说明
scaleToFill不保持纵横比缩放图片,使图片的宽高完全拉伸至填满 image 元素
aspectFit保持纵横比缩放图片,使图片的长边能完全显示出来
aspectFill保持纵横比缩放图片,只保证图片的短边能完全显示出来
widthFix宽度不变,高度自动变化,保持原图宽高比不变
heightFix高度不变,宽度自动变化,保持原图宽高比不变
top不缩放图片,只显示图片的顶部区域
bottom不缩放图片,只显示图片的底部区域
center不缩放图片,只显示图片的中间区域
left不缩放图片,只显示图片的左边区域
right不缩放图片,只显示图片的右边区域
top left不缩放图片,只显示图片的左上边区域
top right不缩放图片,只显示图片的右上边区域
bottom left不缩放图片,只显示图片的左下边区域
bottom right不缩放图片,只显示图片的右下边区域

t-image Events ​

事件名说明回调参数
click点击时触发-
load图片加载完成时触发-
error图片加载失败时触发-
transitionend动画结束时触发-
initFinished组件初始化完成时触发,返回组件节点信息-
touchstart触摸开始时触发-
touchend触摸结束时触发-
touchmove触摸移动时触发-
touchcancel触摸取消时触发-

外部类 ​

类名说明
image-class图片样式
loading-class加载文字样式
placeholder-class占位文字样式

t-image Slots ​

插槽名说明
loading加载中状态插槽
error加载失败状态插槽