|
@@ -0,0 +1,38 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <h1>Part1</h1>
|
|
|
+ <button @click="changeMain">切换</button>
|
|
|
+ <!--
|
|
|
+ vue2:keep-alive
|
|
|
+ <keep-alive>
|
|
|
+ <Demo1 v-if="showMain"></Demo1>
|
|
|
+ <Demo2 v-else></Demo2>
|
|
|
+ </keep-alive> -->
|
|
|
+ <!-- <KeepAlive :include="['Demo2']" > -->
|
|
|
+ <!-- <KeepAlive :exclude="['Demo2']" > -->
|
|
|
+ <KeepAlive>
|
|
|
+ <Demo1 v-show="showMain"></Demo1>
|
|
|
+ </KeepAlive>
|
|
|
+ <!-- <component :is='currentComponent'></component> -->
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import Demo1 from "./components/Demo1.vue";
|
|
|
+import Demo2 from './components/Demo2.vue';
|
|
|
+import { ref, reactive, onMounted, onUnmounted } from "vue";
|
|
|
+let showMain = ref(true);
|
|
|
+let currentComponent = ref(Demo1);
|
|
|
+console.log(currentComponent, "currentComponent");
|
|
|
+onMounted(() => {
|
|
|
+ console.log("part1挂载了");
|
|
|
+});
|
|
|
+onUnmounted(() => {
|
|
|
+ console.log("part1卸载了");
|
|
|
+});
|
|
|
+function changeMain() {
|
|
|
+ showMain.value = !showMain.value
|
|
|
+ // currentComponent.value = JSON.stringify(currentComponent.value) === JSON.stringify(Demo1) ?Demo2:Demo1;
|
|
|
+}
|
|
|
+</script>
|
|
|
+<style lang="scss" scoped></style>
|