037.Vue3入门,动态组件
1、App.vue代码如下:
<template> <component :is="tabComponent"></component> <button @click="change">切换组件</button> </template> <script> import Child1 from "./view/Child1.vue" import Child2 from "./view/Child2.vue" export default { data() { return { tabComponent: "Child1" } }, components: { Child1, Child2 }, methods: { change() { console.log('change', this.tabComponent == "Child1") this.tabComponent = this.tabComponent == "Child1" ? "Child2" : "Child1"; } } } </script>
2、Child1.vue代码如下;
<template> <div>我是子页面1</div> </template> <script> export default { beforeCreate() { console.log('beforeCreate') }, created() { console.log('created') }, beforeMount() { console.log('beforeMount') }, beforeUpdate() { console.log('beforeUpdate') }, beforeDestroy() { console.log('beforeDestroy') }, mounted() { console.log('mounted') }, updated() { console.log('updated') }, destroyed() { console.log('destroyed') }, methods: { change() { console.log('change') } } } </script>
3、Child.vue代码如下:
<template> <div>我是子页面2</div> </template> <script> export default { beforeCreate() { console.log('beforeCreate') }, created() { console.log('created') }, beforeMount() { console.log('beforeMount') }, beforeUpdate() { console.log('beforeUpdate') }, beforeDestroy() { console.log('beforeDestroy') }, mounted() { console.log('mounted') }, updated() { console.log('updated') }, destroyed() { console.log('destroyed') }, methods: { change() { console.log('change') } } } </script>
4、效果如下:
分类:
网站相关 / Vue3基础知识
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2019-08-11 九、航材_航材申请和库房发料
2019-08-11 八、航材_MCC工作指令下发与航材保障
2019-08-11 七、航材_SAP中查看所有件号清单
2019-08-11 六、航材_查看件号修改记录
2019-08-11 五、航材_件号冻结
2019-08-11 四、航材_互换件_添加单向互换
2019-08-11 三、航材_互换件_删除完全互换