问题描述:
动态组件命明明写好了,我这怎么就不展示?比如下面这个,我觉得自己写得非常稳当!!
解决办法:
明明写好了,跟你有什么关系,你又没写好。那怎么办呢,
参考下面这个栗子🌰:
将所有**组件的名字**用**变量**表示,别用字符串,举个🌰如下:
<template>
<div class="app">
<p>App</p>
<button @click="currentPage = Home">home</button>
<button @click="currentPage = About">about</button>
<component :is="currentPage"></component>
</div>
</template>
<script setup>
import { ref } from 'vue'
import About from './views/About.vue'
import Home from './views/Home.vue'
let currentPage = shallowRef(Home)
</script>