# Image 圖片
可預覽的圖片容器。fit 透傳原生 object-fit,preview 開啟點選預覽,previewSrcList 支援多圖翻閱。
圖片
<template>
<div class="demo-col">
<div class="demo-row" style="gap: 24px; flex-wrap: wrap; align-items: flex-start">
<div class="demo-col" style="gap: 8px">
<LhImage :src="src" alt="溪山行旅圖" fit="cover" preview />
<span class="demo-note">cover + 可預覽</span>
</div>
<div class="demo-col" style="gap: 8px">
<LhImage :src="src" alt="contain 模式" fit="contain" />
<span class="demo-note">contain</span>
</div>
<div class="demo-col" style="gap: 8px">
<LhImage :src="src" alt="延遲載入" fit="fill" lazy />
<span class="demo-note">fill + lazy</span>
</div>
</div>
<p class="demo-note">previewSrcList 多圖預覽(點選首圖依次翻閱)</p>
<LhImage :src="src" alt="多圖預覽入口" fit="cover" preview :preview-src-list="gallery" />
</div>
</template>
<script>
export default {
data: () => ({
src: 'data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20width=%27240%27%20height=%27160%27%3E%3Crect%20width=%27240%27%20height=%27160%27%20fill=%27%23e8e2d5%27/%3E%3Cpath%20d=%27M0%20115%20Q60%2080%20120%20115%20T240%20115%20V160%20H0%20Z%27%20fill=%27%23c9c2b2%27/%3E%3Ctext%20x=%2750%%27%20y=%2767%27%20font-size=%2718%27%20fill=%27%232b4c7c%27%20text-anchor=%27middle%27%20font-family=%27serif%27%3E%E6%BA%AA%E5%B1%B1%E8%A1%8C%E6%97%85%E5%9B%BE%3C/text%3E%3C/svg%3E',
gallery: [
'data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20width=%27640%27%20height=%27420%27%3E%3Crect%20width=%27640%27%20height=%27420%27%20fill=%27%23e8e2d5%27/%3E%3Cpath%20d=%27M0%20302%20Q160%20210%20320%20302%20T640%20302%20V420%20H0%20Z%27%20fill=%27%23c9c2b2%27/%3E%3Ctext%20x=%2750%%27%20y=%27176%27%20font-size=%2740%27%20fill=%27%232b4c7c%27%20text-anchor=%27middle%27%20font-family=%27serif%27%3E%E7%AC%AC%E4%B8%80%E5%B9%85%3C/text%3E%3C/svg%3E',
'data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20width=%27640%27%20height=%27420%27%3E%3Crect%20width=%27640%27%20height=%27420%27%20fill=%27%23e8e2d5%27/%3E%3Cpath%20d=%27M0%20302%20Q160%20210%20320%20302%20T640%20302%20V420%20H0%20Z%27%20fill=%27%23c9c2b2%27/%3E%3Ctext%20x=%2750%%27%20y=%27176%27%20font-size=%2740%27%20fill=%27%232b4c7c%27%20text-anchor=%27middle%27%20font-family=%27serif%27%3E%E7%AC%AC%E4%BA%8C%E5%B9%85%3C/text%3E%3C/svg%3E',
'data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20width=%27640%27%20height=%27420%27%3E%3Crect%20width=%27640%27%20height=%27420%27%20fill=%27%23e8e2d5%27/%3E%3Cpath%20d=%27M0%20302%20Q160%20210%20320%20302%20T640%20302%20V420%20H0%20Z%27%20fill=%27%23c9c2b2%27/%3E%3Ctext%20x=%2750%%27%20y=%27176%27%20font-size=%2740%27%20fill=%27%232b4c7c%27%20text-anchor=%27middle%27%20font-family=%27serif%27%3E%E7%AC%AC%E4%B8%89%E5%B9%85%3C/text%3E%3C/svg%3E',
],
}),
}
</script>
# Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| src | 圖片位址 | string | — |
| alt | 替代文字(a11y 強約束,TS 層必填) | string | — |
| fit | 裁切模式(原生 object-fit) | 'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down' | 'cover' |
| preview | 是否可點選預覽 | boolean | false |
| previewSrcList | 預覽圖列表(未傳時退化為 [src]) | string[] | — |
| lazy | 原生延遲載入(loading="lazy") | boolean | false |
| sx | sx 快速佈局屬性 | — | — |
# ImageViewer Props
獨立匯出的預覽器:images(預覽圖列表)、initialIndex(初始下標,預設 0)。
提示
LhImage 的 preview 已內建 viewer,多數場景無需直接使用 LhImageViewer。
Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 |
苏公网安备32040002010537