当前位置:网站首页>Component: is to switch between multiple components
Component: is to switch between multiple components
2022-06-25 13:16:00 【liminla!】
component :is Switch between multiple components
Parent component
<template>
<div>
<div
:class="{ active: index === activeIndex }"
v-for="(item, index) in menuList"
:key="item.name"
@click="tabChange(index, item.name)"
>
{
{
item.name }}
</div>
</div>
<component
:is="menuActive"
:id="id"
:ref="menuActive"
></component>
</div>
</template>
<script>
import A from "./components/a";
import B from "./components/b";
import C from "./components/C";
export default {
components: {
A, B, C},
data() {
return {
id:undefined,
menuActive: "",
menuList:[
{
name:'A',component:'A'},
{
name:'B',component:'B'},
{
name:'C',component:'C'},
]
}
},
mounted() {
this.tabChange(0);
},
methods: {
tabChange(index, item) {
this.menuActive = this.menuList[index].component;
setTimeout(() => {
this.$refs[this.menuActive].init();
}, 20);
},
},
}
</script>
Child components
<template>
<div>
</div>
</template>
<script>
export default {
props: {
id: {
type: String,
default: "",
},
data() {
return {
}
},
mounted() {
},
methods: {
init() {
this.getData();// Call interface to get data
},
},
}
</script>
边栏推荐
- MySQL learning notes
- Maui's learning path (II) -- setting
- 与生产环境中的 console.log 说再见
- RESTful和RPC
- 康威定律,作为架构师还不会灵活运用?
- Koa 框架
- JSTL tag: fmt:formatdate tag format Chinese standard time or timestamp
- Optimization of lazyagg query rewriting in parsing data warehouse
- Analyse de l'optimisation de la réécriture des requêtes lazyagg de l'entrepôt
- 關於數據在內存中的存儲下
猜你喜欢
关于一道教材题的讲解
Conway's law can not be flexibly applied as an architect?
二叉树之_哈夫曼树_哈弗曼编码
康威定律,作为架构师还不会灵活运用?
CUDA error: unspecified launch failure
Three lines of code to simply modify the project code of the jar package
Sword finger offer II 029 Sorted circular linked list
Resolution of PPT paper drawing
揭秘GaussDB(for Redis):全面对比Codis
Serevlt初识
随机推荐
Using CMD (command prompt) to install MySQL & configure the environment
Sword finger offer day 2 linked list (simple)
剑指 Offer II 028. 展平多级双向链表
Three lines of code to simply modify the project code of the jar package
. NET in China - What's New in . NET
Resolution of PPT paper drawing
C# 切换中英文输入法
Fedora 35 deploys DNS master-slave and separation resolution -- the way to build a dream
[turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer
It is extraordinary to make a move, which is very Oracle!
汇编标志位相关知识点(连)
与生产环境中的 console.log 说再见
揭秘GaussDB(for Redis):全面对比Codis
.NET in China - What's New in .NET
剑指 Offer II 029. 排序的循环链表
Solution to Nacos' failure to modify the configuration file mysql8.0
Summer Ending
It's an artifact to launch a website in a few minutes
Maui的学习之路(二)--设置
[machine learning] parameter learning and gradient descent