Image (图片)
带骨架屏、宽高比与 object-fit 的图片;在 Nuxt 层下经由 @nuxt/image 渲染。
基础用法
Basic.vue
宽高比
AspectRatio.vue
填充方式
ObjectFit.vue
骨架屏
Skeleton.vue
ThumbHash 模糊占位(blur-up)
传入 thumbhash(后端随图片元数据下发的 ~25 字节 base64), 加载前即显示解码出的模糊占位、加载完成后淡出——比纯骨架屏更贴近最终画面,且零额外网络请求。 解码器仅在用到时才按需加载,客户端解码、SSR 安全。

BlurUp.vue
加载失败回退

Fallback.vue
load / error 事件
两个事件的签名都是 (src, event?)。第一个参数是对应的图片地址—— 因为配了 fallbackSrc 时会有两次尝试,靠它才能区分是原图失败还是回退图也失败。 event 是原生 DOM 事件;若失败/成功是从已缓存的图片状态直接判定出来的 (此时浏览器不会再触发 load / error),则为 undefined。

等待中…
ErrorEvent.vue
懒加载与即时加载
Loading.vue
属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| src * | string | — | Image URL. Under Nuxt it is handed to the injected `<NuxtImg>`, so a provider path or a remote URL both work. |
| alt | string | "image" | Alternative text. Write the empty string for a decorative image so screen readers skip it. |
| ariaLabel | string | — | Accessible name, when it has to differ from `alt`. |
| aspectRatio | string | — | CSS aspect-ratio on the wrapper, e.g. "16 / 9". When set the image is absolutely positioned and fills the box. |
| className | string | — | Classes for the WRAPPER element (the box that holds the skeleton and the aspect ratio). Extra classes, merged after the component's own classes so yours wins the conflict — KunUI's `rounded-kun-*` / `shadow-kun-*` scales included. |
| decoding | "auto" | "sync" | "async" | — | Native `decoding` hint. `async` keeps a large image from blocking the frame it lands in. |
| densities | string | — | Pixel densities to generate, e.g. `'x1 x2'`, via |
| fallbackSrc | string | — | Shown if `src` fails to load (broken URL, 404). Resets when `src` changes. |
| fetchpriority | "auto" | "high" | "low" | — | Native fetch priority. `high` for the one image that is the page's LCP; leave the rest alone. |
| format | string | — | Output format to transcode to (`webp`, `avif`, …), via |
| height | string | number | — | Intrinsic height. See `width`. |
| imageClassName | string | — | Classes for the inner image (wrapper gets `className`). |
| loading | "lazy" | "eager" | "lazy" | Native loading hint. `lazy` defers the fetch until the image nears the viewport; use `eager` for anything above the fold. |
| objectFit | "fill" | "none" | "cover" | "contain" | "scale-down" | "cover" | How the image fills its box once `aspectRatio` or an explicit size gives it one. |
| placeholder | string | number | boolean | [w: number, h: number, q?: number, b?: number] | — | Blur-up placeholder generated by |
| preload | boolean | { fetchPriority: "auto" | "high" | "low"; } | — | Emit a `<link rel="preload">` for this image, via |
| provider | "none" | (string & {}) | "ipx" | — | Which |
| quality | string | number | — | Compression quality passed to |
| sizes | string | — | Responsive `sizes` hint for |
| skeleton | boolean | true | Renders a sibling skeleton overlay while loading (Radix-Avatar 3-state machine). Default true; set false for a bare element. |
| thumbhash | string | — | A ThumbHash (base64) → a blurred "blur-up" placeholder shown until the image loads, then cross-faded out. Decoded to a tiny image on the client; falls back to the pulse skeleton until decoded (or if the hash is invalid). Implies the wrapper even with `skeleton: false`. |
| width | string | number | — | Intrinsic width. Set it together with `height` so the browser reserves the box and the page does not shift as the image arrives. |
事件
| 事件 | 回调参数 |
|---|---|
| error | src: string, event?: Event |
| load | src: string, event?: Event |