From 12ebceab49c2a56702fffdfc01bb8b0bc3a708ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Sun, 25 Jun 2023 00:01:44 +0800 Subject: [PATCH] feat: add `reload` function (#103) --- src/Repl.vue | 13 ++++++++++++- src/output/Output.vue | 9 ++++++++- src/output/Preview.vue | 9 +++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Repl.vue b/src/Repl.vue index c2c5feb3..dc17f941 100644 --- a/src/Repl.vue +++ b/src/Repl.vue @@ -2,7 +2,7 @@ import SplitPane from './SplitPane.vue' import Output from './output/Output.vue' import { Store, ReplStore, SFCOptions } from './store' -import { provide, toRef } from 'vue' +import { provide, ref, toRef } from 'vue' import type { EditorComponentType } from './editor/types' import EditorContainer from './editor/EditorContainer.vue' @@ -49,6 +49,7 @@ if (!props.editor) { throw new Error('The "editor" prop is now required.') } +const outputRef = ref>() const { store } = props const sfcOptions = (store.options = props.sfcOptions || {}) if (!sfcOptions.script) { @@ -74,6 +75,15 @@ provide('import-map', toRef(props, 'showImportMap')) provide('tsconfig', toRef(props, 'showTsConfig')) provide('clear-console', toRef(props, 'clearConsole')) provide('preview-options', props.previewOptions) + +/** + * Reload the preview iframe + */ +function reload() { + outputRef.value?.reload() +} + +defineExpose({ reload })