From fb8c2b00d9ea88621b6fce3ba27b5f200c08f3ad Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 5 May 2023 14:17:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96sandbox=E7=9A=84=E9=AB=98?= =?UTF-8?q?=E5=BA=A6=E8=87=AA=E9=80=82=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sandbox/index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/sandbox/index.js b/src/sandbox/index.js index a3d63d9..8cf8248 100644 --- a/src/sandbox/index.js +++ b/src/sandbox/index.js @@ -192,7 +192,7 @@ class Sandbox extends Component { contentLoaded(ev) { let elem = ev.target let body = elem.contentDocument.body - elem.style.height = body.clientHeight + 'px' + elem.style.height = body.scrollHeight + 10 + 'px' } renderTemplate() { @@ -207,9 +207,17 @@ class Sandbox extends Component { mounted() { // - this.#cache.preview.panel = this.$refs.preview + let target = this.$refs.preview + this.#cache.preview.panel = target this.renderTemplate() - this.$refs.preview.style.display = 'block' + target.style.display = 'block' + + this.__observer = new ResizeObserver(_ => this.contentLoaded({ target })) + this.__observer.observe(target.contentDocument.body) + } + + unmounted() { + this.__observer?.disconnect() } render() {