Skip to content

FaImage 图片

默认启用懒加载、图片预览和 Teleport,并提供团队图片地址转换与完整 Viewer 插槽。

图片适应、预览与错误插槽

查看代码
Vue
<template>
	<div class="demo-image-grid">
		<div><FaImage :src="image" original fit="cover" style="width: 100%; height: 140px" /><span>Cover + 点击预览</span></div>
		<div><FaImage :src="image" original fit="contain" style="width: 100%; height: 140px" /><span>Contain</span></div>
		<div>
			<FaImage src="invalid-image" original :preview="false" style="width: 100%; height: 140px">
				<template #error><div class="demo-image-error">自定义加载失败</div></template>
			</FaImage>
			<span>错误插槽</span>
		</div>
	</div>
</template>

<script setup lang="ts">
const image = `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(
	'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 360"><defs><linearGradient id="g"><stop stop-color="#409eff"/><stop offset="1" stop-color="#36cfc9"/></linearGradient></defs><rect width="640" height="360" fill="url(#g)"/><circle cx="500" cy="80" r="45" fill="#fff" opacity=".65"/><text x="48" y="205" font-size="54" fill="white">Fast.Element.Plus</text></svg>'
)}`;
</script>

FaImage 完整 API

Props 属性 (24)

Fast 与 Element Plus 2.14.6 的属性已合并展示;Fast 修改项优先排列,未透传的原生属性保留用于兼容性核对。

属性来源说明类型默认值
hideOnClickModalFast 修改点击图片预览遮罩时是否关闭预览。BooleanFasttrueELfalse
srcFast 修改图片地址或 Base64 图片内容。StringFast""EL""
lazyFast 修改是否启用懒加载。BooleanFasttrueELfalse
previewSrcListFast 修改图片预览列表。ArrayFast[]EL[]
previewTeleportedFast 修改图片预览层是否挂载到 body。BooleanFasttrueELfalse
base64Fast 新增将值作为 Base64 图片内容。Booleanfalse
originalFast 新增使用原始图片地址。Booleanfalse
normalFast 新增使用标准图地址后缀。Booleanfalse
smallFast 新增使用小图地址后缀。Booleanfalse
thumbFast 新增使用缩略图地址后缀。Booleanfalse
previewFast 新增是否允许图片预览。Booleantrue
fitEL 原生内容如何适应容器。String""
loadingEL 原生加载状态。String
scrollContainerEL 原生the container to add scroll listener when using lazy load. By default, the container to add scroll listener when using lazy load.String / Object
zIndexEL 原生set image preview z-index.Number
initialIndexEL 原生initial preview image index, less than the length of url-list.Number0
infiniteEL 原生whether the viewer preview is infinite.Booleantrue
closeOnPressEscapeEL 原生whether the image-viewer can be closed by pressing ESC.Booleantrue
zoomRateEL 原生the zoom rate of the image viewer zoom event.Number1.2
scaleEL 原生the preview image scale.Number1
minScaleEL 原生the min scale of the image viewer zoom event.Number0.2
maxScaleEL 原生the max scale of the image viewer zoom event.Number7
showProgressEL 原生whether to display the preview image progress content.Booleanfalse
crossoriginEL 原生native attribute crossorigin.String
Events 事件(5)
名称来源说明参数 / 类型
loadEL 原生资源加载成功时触发。
errorEL 原生资源加载或组件处理失败时触发。
switchEL 原生图片预览器切换当前图片时触发。
closeEL 原生关闭流程完成时触发。
showEL 原生图片预览器显示时触发。
Slots 插槽(7)
名称来源说明参数 / 类型
placeholderEL 原生图片加载过程中的占位内容。
errorEL 原生表单校验错误或图片加载失败时的自定义内容。
viewer({ src })EL 原生自定义图片预览器内容。({ src })
progressEL 原生自定义图片加载进度内容。
toolbarEL 原生自定义图片预览工具栏。
viewer-errorEL 原生图片预览器加载失败时的自定义内容。
image viewer slotsEL 原生 · 未透传when you allow big image preview, image viewer slots all can be used.
Expose 暴露(1)
名称来源说明参数 / 类型
showPreviewEL 原生打开 ElImage 图片预览器。

FaImage 实例方法

showPreview 预览

手动打开图片预览。

签名

ts
showPreview(): void;

示例

vue
<template>
	<FaImage ref="componentRef" />
</template>

<script setup lang="ts">
import { ref } from "vue";
import { FaImage } from "fast-element-plus";

const componentRef = ref<InstanceType<typeof FaImage>>();
componentRef.value?.showPreview();
</script>

输入

该方法没有输入参数。

返回

返回值返回值类型返回值说明
resultvoid没有返回值。