vue3动态引入组件
时间: 2023-10-05 09:06:51 浏览: 334
Vue3中可以通过使用`defineAsyncComponent`方法来实现动态引入组件。具体写法如下:
```javascript
import { defineAsyncComponent } from 'vue'
const AsyncComp = defineAsyncComponent(() => import('./components/MyComponent.vue'))
```
这样就可以在需要的时候动态加载`MyComponent.vue`组件了。使用`AsyncComp`即可引用该组件。
通过异步加载组件的方法,我们可以在某个事件触发后动态加载相应的组件,从而实现组件的动态渲染。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Vue3 —— 在vue中动态引入组件以及动态引入js的方法](https://blog.csdn.net/Bonsoir777/article/details/128217232)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [vue3动态加载组件](https://blog.csdn.net/qq_41839808/article/details/126932705)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文