vue使用动态组件实现TAB切换效果完整实例(vue中动态组件)真没想到

随心笔谈2年前发布 编辑
154 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

<template>
<div id=”app”>
<div class=”top”>
<div
class=”crad”
:class=”{ highLight: whichIndex==index }”
v-for=”(item, index) in cardArr”
:key=”index”
@click=”
whichIndex=index;
componentId=item.componentId;

>
{{ item.componentName }}
</div>
</div>
<div class=”bottom”>
<keep-alive>
<component :is=”componentId”></component>
</keep-alive>
</div>
</div>
</template>
<script>
import one from “https://www.jb51.net/article/components/one”;
import two from “https://www.jb51.net/article/components/two”;
import three from “https://www.jb51.net/article/components/three”;
import four from “https://www.jb51.net/article/components/four”;
export default {
components: {
one,
two,
three,
four,
},
data() {
return {
whichIndex: 0,
componentId: “one”,
cardArr: [
{
componentName: “动态组件一”,
componentId: “one”,
},
{
componentName: “动态组件二”,
componentId: “two”,
},
{
componentName: “动态组件三”,
componentId: “three”,
},
{
componentName: “动态组件四”,
componentId: “four”,
},
],
};
},
};
</script>
<style lang=”less” scoped>
#app {
width: 100%;
height: 100vh;
box-sizing: border-box;
padding: 50px;
.top {
width: 100%;
height: 80px;
display: flex;
justify-content: space-around;
.crad {
width: 20%;
height: 80px;
line-height: 80px;
text-align: center;
background-color: #fff;
border: 1px solid #e9e9e9;
}
.highLight {
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
transform: translate3d(0, -1px, 0);
}
}
.bottom {
margin-top: 20px;
width: 100%;
height: calc(100% – 100px);
border: 3px solid pink;
display: flex;
justify-content: center;
align-items: center;
}
}
</style>

© 版权声明

相关文章