From 31fb2f10a18a2508d5753967db11edeb7aabcd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=89=E4=BB=94?= <1414589221@qq.com> Date: Thu, 11 May 2023 23:01:32 +0800 Subject: [PATCH] fix(image): `fallback-src` prop and lazy loading dosen't work (#4485) * fix(image): `fallback-src` prop and lazy loading dosen't work, close #4480 * Update src/image/demos/zhCN/lazy.demo.vue --------- Co-authored-by: 07akioni <07akioni2@gmail.com> --- CHANGELOG.en-US.md | 2 ++ CHANGELOG.zh-CN.md | 1 + src/image/demos/enUS/index.demo-entry.md | 3 +- src/image/demos/enUS/lazy.demo.vue | 18 ++++++++++- src/image/demos/zhCN/index.demo-entry.md | 2 +- src/image/demos/zhCN/lazy.demo.vue | 19 ++++++++++- src/image/src/Image.tsx | 41 ++++++++++++------------ 7 files changed, 61 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 31041bd8935..91f917972b2 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -9,10 +9,12 @@ - Fix `n-dynamic-input` doesn't return correct `index` in `on-create` callback. - Fix `trTR` i18n, closes [#4231](https://github.com/tusen-ai/naive-ui/issues/4231). - Fix `n-input`'s show password icon is offset when use both `password` and `disabled`, closes [#4364](https://github.com/tusen-ai/naive-ui/issues/4364). +- Fix `n-image` set `fallback-src` prop and lazy loading dosen't work, closes[#4480](https://github.com/tusen-ai/naive-ui/issues/4480) - Fix `n-upload` warning cause by extraneous non-props attributes were passed to vue component `TransitionGroup` but could not be automatically inherited, closes [#4447](https://github.com/tusen-ai/naive-ui/issues/4447). - Fix `n-menu` `show` `default` attribute spelling problem, closes [#4750](https://github.com/tusen-ai/naive-ui/issues/4750). - Fix `n-icon-wrapper`'s theme error, closes [#4768](https://github.com/tusen-ai/naive-ui/issues/4768). + ### Feats - `n-dynamic-input` adds `action` slot, closes [#3981](https://github.com/tusen-ai/naive-ui/issues/3981). diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index b6deaf164bb..c2ebf9ef8e6 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -9,6 +9,7 @@ - 修复 `n-dynamic-input` 在点击添加按钮后 `on-create` 返回的 `index` 不正确 - 修复 `trTR` 国际化,关闭 [#4231](https://github.com/tusen-ai/naive-ui/issues/4231) - 修复 `n-input` 同时使用 `password` 和 `disabled` 时,显示密码图标偏移的问题,关闭 [#4364](https://github.com/tusen-ai/naive-ui/issues/4364) +- 修复 `n-image` 设置 `fallback-src` 属性和懒加载无效,closes[#4480](https://github.com/tusen-ai/naive-ui/issues/4480) - 修复 `n-upload` 内部使用 vue `TransitionGroup` 组件时, 传递了未声明的 prop 且未被自动继承导致警告, 关闭[#4447](https://github.com/tusen-ai/naive-ui/issues/4447) - 修复 `n-menu` `show` `default` 属性拼写问题,关闭 [#4750](https://github.com/tusen-ai/naive-ui/issues/4750) - 修复 `n-icon-wrapper` 的主题异常,关闭 [#4768](https://github.com/tusen-ai/naive-ui/issues/4768) diff --git a/src/image/demos/enUS/index.demo-entry.md b/src/image/demos/enUS/index.demo-entry.md index 84211309105..5319dc85cfd 100644 --- a/src/image/demos/enUS/index.demo-entry.md +++ b/src/image/demos/enUS/index.demo-entry.md @@ -25,7 +25,8 @@ previewed-img-props.vue | fallback-src | `string` | `undefined` | URL to show when the image fails to load. | | | height | `string \| number` | `undefined` | Image height. | | | img-props | `object` | `undefined` | The props of the img element inside the component. | | -| lazy | `boolean` | `false` | Whether to show after it enters viewport configured by `intersection-observer-options` | 2.30.5 | +| lazy | `boolean` | `false` | Load image after it enters viewport. When used alone, it will be assigned the property value of [HTMLImageElement.loading](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading). Alternatively, it can be used in conjunction with the `intersection-observer-options` configuration to achieve lazy loading. | +| 2.30.5 | | intersection-observer-options | `{ root?: Element \| Document \| string \| null, rootMargin?: string, threshold?: number \| number[]; }` | `undefined` | Intersection observer's config to be applied when `lazy=true`. | 2.30.5 | | object-fit | `'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down'` | `fill` | Object-fit type of the image in the container. | | | preview-src | `string` | `undefined` | Source of preview image. | | diff --git a/src/image/demos/enUS/lazy.demo.vue b/src/image/demos/enUS/lazy.demo.vue index 19efdfad2ba..9d37021b7db 100644 --- a/src/image/demos/enUS/lazy.demo.vue +++ b/src/image/demos/enUS/lazy.demo.vue @@ -1,10 +1,26 @@ # Lazy load -You can use `lazy` to let image load after it enters viewport. +Load the images only after they enter the viewport. There are two ways to use it: one is to use the `lazy` property alone, which will be set to the value of the [HTMLImageElement.loading](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading) property, and the other is to use `lazy` together with the `intersection-observer-options` configuration to implement lazy loading using the [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) API.