From 092aaff8b12b9bdcdc3c336309971f7be6b839a7 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 9 Dec 2024 11:35:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81,=20?= =?UTF-8?q?=E5=87=8F=E5=B0=91=E4=BD=93=E7=A7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/router/router-components.js | 35 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 451c3cf..36a73d3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wkitd", - "version": "1.3.11", + "version": "1.3.12", "type": "module", "main": "dist/index.js", "files": [ diff --git a/src/router/router-components.js b/src/router/router-components.js index d266365..9cf383e 100644 --- a/src/router/router-components.js +++ b/src/router/router-components.js @@ -21,13 +21,16 @@ class RouterView extends Component { set current(v) { let old = this.#current + let $refs = this.$refs this.#current = v + if (this.keepAlive) { if (old) { - if (this.$refs[old]) { - this.$refs[old].removed = true - this.$refs[old].deactivated() - this.$refs[old].remove() + let $old = $refs[old] + if ($old) { + $old.removed = true + $old.deactivated() + $old.remove() } else { this.$requestUpdate() } @@ -35,14 +38,15 @@ class RouterView extends Component { this.$requestUpdate() } if (v) { - if (this.$refs[v]) { - this.root.appendChild(this.$refs[v]) - this.$refs[v].$requestUpdate() + let $new = $refs[v] + if ($new) { + this.root.appendChild($new) + $new.$requestUpdate() if (this.transition) { - this.$refs[v].$animate() + $new.$animate() } - this.$refs[v].removed = false - this.$refs[v].activated() + $new.removed = false + $new.activated() } else { this.$requestUpdate() } @@ -72,20 +76,21 @@ class RouterView extends Component { { transform: 'translateX(0)', opacity: 1 } ] } + let name = this.current - if (this.current) { + if (name) { if (this.transition) { return raw( - `<${this.current} ref="${this.current}" ${ + `<${name} ref="${name}" ${ this.keepAlive ? 'keep-alive' : '' - } #animation="%s">`, + } #animation="%s">`, [option] ) } return raw( - `<${this.current} ref="${this.current}" ${ + `<${name} ref="${name}" ${ this.keepAlive ? 'keep-alive' : '' - }>` + }>` ) } }