Skip to content

Commit

Permalink
fix(webview): Image 的 src 被清空时没有去掉之前的图片
Browse files Browse the repository at this point in the history
  • Loading branch information
yizhi996 committed Aug 29, 2022
1 parent 78a98a6 commit 7dd227e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions packages/webview/src/element/components/Image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineComponent({
const container = ref<HTMLElement>()
const imageEl = ref<HTMLElement>()

let imageSize = { width: 0, height: 0 }
const imageSize = { width: 0, height: 0 }

watch(
() => props.mode,
Expand Down Expand Up @@ -57,12 +57,24 @@ export default defineComponent({
})

const getSrc = () => {
const { src, webp } = props
if (!src) {
imageSize.width = 0
imageSize.height = 0
if (imageEl.value) {
imageEl.value.style.backgroundImage = ""
}
if (container.value) {
container.value.style.width = ""
container.value.style.height = ""
}
}
if (isDevtools) {
return props.src
} else if (props.webp) {
return "webp" + props.src
return src
} else if (webp) {
return "webp" + src
}
return props.src
return src
}

onMounted(() => {
Expand Down Expand Up @@ -123,10 +135,10 @@ export default defineComponent({

const lazyLoadImage = () => {
const src = getSrc()
if (!container.value || !src) {
if (!src) {
return
}
addIntersectionObserve(container.value, src, onLoad)
container.value && addIntersectionObserve(container.value, src, onLoad)
}

const immediateLoadImage = () => {
Expand Down

0 comments on commit 7dd227e

Please sign in to comment.