chore(sfc-playground): teardown preview update watcher
This commit is contained in:
parent
ebf396251c
commit
7bc5fd9a04
@ -12,6 +12,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Message from '../Message.vue'
|
import Message from '../Message.vue'
|
||||||
import { ref, onMounted, onUnmounted, watchEffect } from 'vue'
|
import { ref, onMounted, onUnmounted, watchEffect } from 'vue'
|
||||||
|
import type { WatchStopHandle } from 'vue'
|
||||||
import srcdoc from './srcdoc.html?raw'
|
import srcdoc from './srcdoc.html?raw'
|
||||||
import { PreviewProxy } from './PreviewProxy'
|
import { PreviewProxy } from './PreviewProxy'
|
||||||
import { MAIN_FILE, SANDBOX_VUE_URL } from '../sfcCompiler'
|
import { MAIN_FILE, SANDBOX_VUE_URL } from '../sfcCompiler'
|
||||||
@ -22,6 +23,7 @@ const runtimeError = ref()
|
|||||||
const runtimeWarning = ref()
|
const runtimeWarning = ref()
|
||||||
|
|
||||||
let proxy: PreviewProxy
|
let proxy: PreviewProxy
|
||||||
|
let updateHandle: WatchStopHandle
|
||||||
|
|
||||||
async function updatePreview() {
|
async function updatePreview() {
|
||||||
runtimeError.value = null
|
runtimeError.value = null
|
||||||
@ -93,12 +95,13 @@ onMounted(() => {
|
|||||||
|
|
||||||
iframe.value.addEventListener('load', () => {
|
iframe.value.addEventListener('load', () => {
|
||||||
proxy.handle_links()
|
proxy.handle_links()
|
||||||
watchEffect(updatePreview)
|
updateHandle = watchEffect(updatePreview)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
proxy.destroy()
|
proxy.destroy()
|
||||||
|
updateHandle && updateHandle()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user