调整keepAlive逻辑

master 1.1.3
yutent 2023-09-19 11:57:57 +08:00
parent d1e81474c0
commit 5e9dd986df
2 changed files with 14 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "wkitd", "name": "wkitd",
"version": "1.1.2", "version": "1.1.3",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",
"files": [ "files": [

View File

@ -5,7 +5,6 @@ import { __ROUTER_VIEW__ } from '../constants.js'
class RouterView extends Component { class RouterView extends Component {
static props = { static props = {
keepAlive: false,
transition: false, transition: false,
current: { current: {
type: String, type: String,
@ -49,16 +48,20 @@ class RouterView extends Component {
] ]
} }
if (this.keepAlive) { if (this.keepAlive) {
let template = this.#views.map(it => [ let template = this.#views.map(it =>
this.transition this.transition
? `<${it} ref="${it}" :__keep_alive__="%s" #animation="%s" style="%s"></${it}>` ? [
: `<${it} ref="${it}" :__keep_alive__="%s" style=%s></${it}>`, `<${it} ref="${it}" keep-alive #animation="%s" style="%s"></${it}>`,
[ [
this.current === it,
{ ...option, immediate: this.current === it }, { ...option, immediate: this.current === it },
this.current === it ? '' : 'display:none' this.current === it ? '' : 'display:none'
] ]
]) ]
: [
`<${it} ref="${it}" keep-alive style=%s></${it}>`,
[this.current === it ? '' : 'display:none']
]
)
return raw( return raw(
template.map(it => it[0]).join(''), template.map(it => it[0]).join(''),