diff --git a/docs/en-US/component/image.md b/docs/en-US/component/image.md index 12d76da95f..5e07bf0684 100644 --- a/docs/en-US/component/image.md +++ b/docs/en-US/component/image.md @@ -69,6 +69,7 @@ image/image-preview | scroll-container | the container to add scroll listener when using lazy load. By default, the container to add scroll listener when using lazy load. | ^[string] / ^[object]`HTMLElement` | — | | alt | native attribute `alt`. | ^[string] | — | | referrerpolicy | native attribute [referrerPolicy](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy). | ^[string] | — | +| crossorigin | native attribute [crossorigin](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin). | ^[enum]`'' \| 'anonymous' \| 'use-credentials'` | 'anonymous' | — | | preview-src-list | allow big image preview. | ^[object]`string[]` | [] | | z-index | set image preview z-index. | ^[number] | — | | initial-index | initial preview image index, less than the length of `url-list`. | ^[number] | 0 | diff --git a/packages/components/image-viewer/src/image-viewer.ts b/packages/components/image-viewer/src/image-viewer.ts index c5fea656b7..695c49aadd 100644 --- a/packages/components/image-viewer/src/image-viewer.ts +++ b/packages/components/image-viewer/src/image-viewer.ts @@ -78,6 +78,13 @@ export const imageViewerProps = buildProps({ type: Number, default: 7, }, + /** + * @description set HTML attribute: crossorigin. + */ + crossorigin: { + type: definePropType<'anonymous' | 'use-credentials' | ''>(String), + default: 'anonymous', + }, } as const) export type ImageViewerProps = ExtractPropTypes diff --git a/packages/components/image-viewer/src/image-viewer.vue b/packages/components/image-viewer/src/image-viewer.vue index 3784116199..c7fa15c9ab 100644 --- a/packages/components/image-viewer/src/image-viewer.vue +++ b/packages/components/image-viewer/src/image-viewer.vue @@ -55,6 +55,7 @@ :src="url" :style="imgStyle" :class="ns.e('img')" + :crossorigin="crossorigin" @load="handleImgLoad" @error="handleImgError" @mousedown="handleMouseDown" @@ -126,6 +127,7 @@ const imgRefs = ref([]) const scopeEventListener = effectScope() const loading = ref(true) +const crossorigin = ref(props.crossorigin) const activeIndex = ref(props.initialIndex) const mode = shallowRef(modes.CONTAIN) const transform = ref({ diff --git a/packages/components/image/src/image.ts b/packages/components/image/src/image.ts index 6d683119cb..4cc7823b03 100644 --- a/packages/components/image/src/image.ts +++ b/packages/components/image/src/image.ts @@ -103,6 +103,13 @@ export const imageProps = buildProps({ type: Number, default: 7, }, + /** + * @description set HTML attribute: crossorigin. + */ + crossorigin: { + type: definePropType<'anonymous' | 'use-credentials' | ''>(String), + default: 'anonymous', + }, } as const) export type ImageProps = ExtractPropTypes diff --git a/packages/components/image/src/image.vue b/packages/components/image/src/image.vue index d0b4f03d9e..3054bdfa0f 100644 --- a/packages/components/image/src/image.vue +++ b/packages/components/image/src/image.vue @@ -11,6 +11,7 @@ :loading="loading" :style="imageStyle" :class="imageKls" + :crossorigin="crossorigin" @click="clickHandler" @load="handleLoad" @error="handleError" @@ -84,6 +85,7 @@ const rawAttrs = useRawAttrs() const attrs = useAttrs() const imageSrc = ref() +const crossorigin = ref(props.crossorigin) const hasLoadError = ref(false) const isLoading = ref(true) const showViewer = ref(false)