|
@@ -9,6 +9,7 @@ import {
|
|
|
template,
|
|
template,
|
|
|
defineVaporAsyncComponent,
|
|
defineVaporAsyncComponent,
|
|
|
onUnmounted,
|
|
onUnmounted,
|
|
|
|
|
+ onUpdated,
|
|
|
} from 'vue'
|
|
} from 'vue'
|
|
|
const show = ref(true)
|
|
const show = ref(true)
|
|
|
const toggle = ref(true)
|
|
const toggle = ref(true)
|
|
@@ -31,6 +32,7 @@ let calls = {
|
|
|
showAppear: [],
|
|
showAppear: [],
|
|
|
notEnter: [],
|
|
notEnter: [],
|
|
|
|
|
|
|
|
|
|
+ updated: [],
|
|
|
unmount: [],
|
|
unmount: [],
|
|
|
}
|
|
}
|
|
|
window.getCalls = key => calls[key]
|
|
window.getCalls = key => calls[key]
|
|
@@ -117,6 +119,42 @@ const click = () => {
|
|
|
includeRef.value = []
|
|
includeRef.value = []
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+const CompA = defineVaporComponent({
|
|
|
|
|
+ name: 'CompA',
|
|
|
|
|
+ setup() {
|
|
|
|
|
+ onUpdated(() => {
|
|
|
|
|
+ calls.updated.push('CompA updated')
|
|
|
|
|
+ })
|
|
|
|
|
+ return template('<div>CompA</div>')()
|
|
|
|
|
+ },
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+const CompB = defineVaporComponent({
|
|
|
|
|
+ name: 'CompB',
|
|
|
|
|
+ setup() {
|
|
|
|
|
+ return template('<div>CompB</div>')()
|
|
|
|
|
+ },
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+const CompC = defineVaporComponent({
|
|
|
|
|
+ name: 'CompC',
|
|
|
|
|
+ setup() {
|
|
|
|
|
+ onUnmounted(() => {
|
|
|
|
|
+ calls.unmount.push('CompC unmounted')
|
|
|
|
|
+ })
|
|
|
|
|
+ return template('<div>CompC</div>')()
|
|
|
|
|
+ },
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+const includeToChange = ref(['CompA', 'CompB', 'CompC'])
|
|
|
|
|
+const currentView = shallowRef(CompA)
|
|
|
|
|
+const switchToB = () => (currentView.value = CompB)
|
|
|
|
|
+const switchToC = () => (currentView.value = CompC)
|
|
|
|
|
+const switchToA = () => {
|
|
|
|
|
+ currentView.value = CompA
|
|
|
|
|
+ includeToChange.value = ['CompA']
|
|
|
|
|
+}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
<template>
|
|
@@ -545,6 +583,18 @@ const click = () => {
|
|
|
</div>
|
|
</div>
|
|
|
<button @click="click">button</button>
|
|
<button @click="click">button</button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ <div class="keep-alive-update-include">
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <transition mode="out-in">
|
|
|
|
|
+ <KeepAlive :include="includeToChange">
|
|
|
|
|
+ <component :is="currentView" />
|
|
|
|
|
+ </KeepAlive>
|
|
|
|
|
+ </transition>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <button id="switchToB" @click="switchToB">switchToB</button>
|
|
|
|
|
+ <button id="switchToC" @click="switchToC">switchToC</button>
|
|
|
|
|
+ <button id="switchToA" @click="switchToA">switchToA</button>
|
|
|
|
|
+ </div>
|
|
|
<!-- with keep-alive end -->
|
|
<!-- with keep-alive end -->
|
|
|
|
|
|
|
|
<!-- vdom interop -->
|
|
<!-- vdom interop -->
|