Skip to content

Commit 879be3c

Browse files
authored
fix(components): [image] fix attrs (element-plus#7451)
closes element-plus#7242
1 parent 281249c commit 879be3c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/components/image/src/image.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@
3636
</template>
3737

3838
<script lang="ts" setup>
39-
import { computed, nextTick, onMounted, ref, watch } from 'vue'
39+
import {
40+
computed,
41+
nextTick,
42+
onMounted,
43+
ref,
44+
useAttrs as useRawAttrs,
45+
watch,
46+
} from 'vue'
4047
import {
4148
isBoolean,
4249
isClient,
@@ -62,6 +69,7 @@ import type { CSSProperties, StyleValue } from 'vue'
6269
6370
defineOptions({
6471
name: 'ElImage',
72+
inheritAttrs: false,
6573
})
6674
6775
const props = defineProps(imageProps)
@@ -82,8 +90,9 @@ useDeprecated(
8290
8391
const { t } = useLocale()
8492
const ns = useNamespace('image')
85-
93+
const rawAttrs = useRawAttrs()
8694
const attrs = useAttrs()
95+
8796
const hasLoadError = ref(false)
8897
const loading = ref(true)
8998
const imgWidth = ref(0)
@@ -95,7 +104,7 @@ const _scrollContainer = ref<HTMLElement | Window>()
95104
let stopScrollListener: () => void
96105
let stopWheelListener: () => void
97106
98-
const containerStyle = computed(() => attrs.value.style as StyleValue)
107+
const containerStyle = computed(() => rawAttrs.style as StyleValue)
99108
100109
const imageStyle = computed<CSSProperties>(() => {
101110
const { fit } = props
@@ -149,7 +158,7 @@ const loadImage = () => {
149158
150159
// bind html attrs
151160
// so it can behave consistently
152-
Object.entries(attrs.value).forEach(([key, value]) => {
161+
Object.entries(rawAttrs).forEach(([key, value]) => {
153162
// avoid onload to be overwritten
154163
if (key.toLowerCase() === 'onload') return
155164
img.setAttribute(key, value as string)

0 commit comments

Comments
 (0)