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

随心笔谈12个月前发布 admin
91 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>

© 版权声明

相关文章