提交 3c23dcbd 编写于 作者: U u014071104

Auto Commit

上级 79c5bd79
<script setup> <script setup>
import HelloWorld from './components/HelloWorld.vue' import ParentOne from './ParentOne.vue';
import TheWelcome from './components/TheWelcome.vue' import ParentTwo from './ParentTwo.vue';
import ChildOne from './ChildOne.vue';
import ChildTwo from './ChildTwo.vue';
import {shallowRef} from "vue"
const parentCom=shallowRef(ParentOne)
const ChildCom=shallowRef(ChildOne)
var parent=1;
var child=1;
const changeParent=()=>{
parent=parent==1?2:1
parentCom.value=parent==1?ParentOne:ParentTwo;
}
const changeChild=()=>{
child=child==1?2:1
ChildCom.value=child==1?ChildOne:ChildTwo;
}
</script> </script>
<template> <template>
<header> <button @click="changeParent">改父组件</button>
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" /> <button @click="changeChild">改子组件</button>
<Suspense>
<div class="wrapper"> <component :is="parentCom">
<HelloWorld msg="You did it!" /> <Suspense>
</div> <keep-alive>
</header> <component :is="ChildCom" />
</keep-alive>
<main>
<TheWelcome /> </Suspense>
</main> </component>
</Suspense>
</template> </template>
<style scoped>
header {
line-height: 1.5;
}
.logo {
display: block;
margin: 0 auto 2rem;
}
@media (min-width: 1024px) {
header {
display: flex;
place-items: center;
padding-right: calc(var(--section-gap) / 2);
}
.logo {
margin: 0 2rem 0 0;
}
header .wrapper {
display: flex;
place-items: flex-start;
flex-wrap: wrap;
}
}
</style>
<template>
<div class="about">
<h1>子组件一 {{ count }}</h1>
<button @click="count++">++</button>
</div>
</template>
<script setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
const count=ref(0)
onMounted(()=>{
console.log("子组件一挂载")
})
onBeforeUnmount(()=>{
console.error("子组件一卸载")
})
</script>
<style scoped>
.about{
width: 200px;
background-color: pink;
}
</style>
\ No newline at end of file
<template>
<div class="about">
<h1>子组件two</h1>
</div>
</template>
<script setup>
import { onBeforeUnmount, onMounted } from 'vue';
onMounted(()=>{
console.log("子组件二挂载")
})
onBeforeUnmount(()=>{
console.error("子组件二卸载")
})
</script>
<style scoped>
.about{
width: 200px;
background-color: palegoldenrod;
}
</style>
\ No newline at end of file
<template>
<div class="about">
<h1>父组件一</h1>
<slot/>
</div>
</template>
<script setup>
import { onBeforeUnmount, onMounted } from 'vue';
onMounted(()=>{
console.log("父组件一挂载")
})
onBeforeUnmount(()=>{
console.error("父组件一卸载")
})
</script>
<style scoped>
.about{
width: 300px;
border:1px solid blue;
background-color: pink;
}
h1{
width: 100%;
background-color: pink;
}
</style>
\ No newline at end of file
<template>
<div class="about">
<h1>父组件二</h1>
<slot/>
</div>
</template>
<script setup>
import { onBeforeUnmount, onMounted } from 'vue';
onMounted(()=>{
console.log("父组件二挂载")
})
onBeforeUnmount(()=>{
console.error("父组件二卸载")
})
</script>
<style scoped>
.about{
width: 300px;
border:1px solid red;
background-color: palegoldenrod;
}
h1{
width: 100%;
background-color: palegoldenrod;
}
</style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册