Wed Jun 7 10:35:00 UTC 2023 inscode

上级 91ad1bd7
...@@ -3,32 +3,22 @@ ...@@ -3,32 +3,22 @@
<h1>App 根组件</h1> <h1>App 根组件</h1>
<hr /> <hr />
<button @click="currentComponent = 'Left'">展示左组件</button>
<button @click="currentComponent = 'Right'">展示右组件</button>
<div class="box">
<!-- 渲染 Left 组件和 Right 组件 -->
<KeepAlive exclude="myRight">
<component :is="currentComponent"></component>
</KeepAlive>
<div class="box">
<Left>
<p> 内容会被丢弃 </p>
</Left>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import Left from './components/Left.vue'; import Left from './components/Left.vue'
import Right from './components/Right.vue';
export default { export default {
data() {
return {
currentComponent: '',
}
},
components: { components: {
Left, Left,
Right
} }
} }
</script> </script>
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
<div class="left-container"> <div class="left-container">
<h3>Left 组件</h3> <h3>Left 组件</h3>
<p>计数器的值为: {{ count }}</p> <slot></slot>
<button @click="count+=1">+1</button>
</div> </div>
</template> </template>
...@@ -15,7 +13,7 @@ export default { ...@@ -15,7 +13,7 @@ export default {
count:0, count:0,
} }
}, },
name:'myLeft', name:'MyLeft',
} }
</script> </script>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<script> <script>
export default { export default {
name:'myRight' name:'MyRight'
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册