fix(image): avoid onload to be overwritten (#1689)

This commit is contained in:
inottn
2021-03-26 14:00:19 +08:00
committed by GitHub
parent 178c39171a
commit d345e65296
2 changed files with 15 additions and 0 deletions

View File

@@ -99,5 +99,18 @@ describe('Image.vue', () => {
expect(result).toBeTruthy()
})
test('emit load event', async () => {
const handleLoad = jest.fn()
const wrapper = mount(Image, {
props: {
src: IMAGE_SUCCESS,
onLoad: handleLoad,
},
})
await doubleWait()
expect(wrapper.find('.el-image__inner').exists()).toBe(true)
expect(handleLoad).toBeCalled()
})
//@todo lazy image test
})

View File

@@ -185,6 +185,8 @@ export default defineComponent({
// so it can behave consistently
Object.keys(attributes)
.forEach(key => {
// avoid onload to be overwritten
if (key.toLowerCase() === 'onload') return
const value = attributes[key]
img.setAttribute(key, value)
})