console
const { createApp, reactive, toRefs, ref } = Vue;
const vue3Composition = {
setup(){
const data = reactive({
name: '张三',
age : 24
})
let component = ref('componentA')
const testMethod = () => {
const name = component.value === 'componentA' ? 'componentB' : 'componentA'
component.value = name
}
const dataRef = toRefs(data);
return {
...dataRef,
component,
testMethod
}
}
}
const app = createApp(vue3Composition).use(ElementPlus)
app.component('componentA', {
template: `我是动态组件A`
})
app.component('componentB', {
template: `我是动态组件B`
})
app.mount('#root');
<div id="root">
<el-button type="primary" @click="testMethod()">测试</el-button>
<component :is='component'></component>
</div>
#map {
width: 100%;
height: 100%;
}