This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: iframe refresh on resize (#531)
- Loading branch information
Showing
4 changed files
with
33 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,49 @@ | ||
<script setup lang="ts"> | ||
import { useDebounceFn, useResizeObserver } from '@vueuse/core' | ||
type Props = { | ||
src: string | ||
allow?: string | ||
referrerpolicy?: IframeReferrerPolicy | ||
allowfullscreen?: boolean | ||
widget?: GridWidget | ||
} | ||
const props = defineProps<Props>() | ||
const embedSrc = ref(props.src) | ||
const iframeRef = ref<HTMLElement | null>(null) | ||
const isLoaded = ref(false) | ||
const handleLoad = () => { | ||
isLoaded.value = true | ||
} | ||
const reloadIframe = () => { | ||
embedSrc.value = '' | ||
const onResize = useDebounceFn(() => { | ||
embedSrc.value = props.src | ||
}, 100) | ||
onResize() | ||
} | ||
defineProps<Props>() | ||
useResizeObserver(iframeRef, useDebounceFn(reloadIframe, 100)) | ||
</script> | ||
|
||
<template> | ||
<div class="h-full p-3"> | ||
<div ref="iframeRef" class="relative h-full p-3"> | ||
<AppLoader | ||
v-if="!isLoaded" | ||
class="absolute left-[calc(50%-20px)] top-[calc(50%-20px)]" | ||
/> | ||
<iframe | ||
:src="src" | ||
:src="embedSrc" | ||
:allow="allow" | ||
:referrerpolicy="referrerpolicy" | ||
:allowfullscreen="allowfullscreen" | ||
frameborder="0" | ||
loading="lazy" | ||
class="size-full overflow-hidden rounded-8" | ||
></iframe> | ||
@load="handleLoad" | ||
> | ||
</iframe> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters