前端Vue实现tabbar组件
tabbar组件的实现TabBar.vue组件tabbar组件只需要在内写一个插槽即可,将来往里面放tabbaritem即可<template><div id='tab-bar'><slot></slot></div></template><script>expor...
·
tabbar组件的实现
TabBar.vue组件
tabbar组件只需要在内写一个插槽即可,将来往里面放tabbaritem即可
<template>
<div id='tab-bar'>
<slot></slot>
</div>
</template>
<script>
export default {
name: 'TabBar',
props:{
},
data () {
return {
}
}
}
</script>
<style scoped>
#tab-bar {
display: flex;
background-color: #f6f6f6;
position: fixed;
left: 0;
right: 0;
bottom: 0;
box-shadow: 0px -1px 1px rgba(100, 100, 100, 0.08)
}
</style>
TabBarItem组件
TabBarItem组件主要为TabBar内部的子组件将来项目需要放多少个就可以放多少个,并且点击的时候将会跳转到对应的路由当中
<template>
<div class="tab-bar-item" @click="itemClick">
<template v-if="!isActive"><slot name="item-icon"></slot></template>
<template v-else><slot name="item-icon-active"></slot></template>
<div :style="this.activeStyle"><slot name="item-text"></slot></div>
</div>
</template>
<script>
export default {
name: 'TabBarItem',
props: {
path: String,
activeColor: {
type: String,
default: 'red'
}
},
data () {
return {
}
},
computed: {
isActive() {
return this.$route.path.indexOf(this.path) != -1;
},
activeStyle() {
return this.isActive ? {color: this.activeColor} : {};
},
},
methods:{
itemClick() {
this.$router.push(this.path);
}
}
}
</script>
<style scoped>
.tab-bar-item {
flex: 1;
height: 49px;
text-align: center;
font-size: 14px;
}
.tab-bar-item img {
width: 24px;
height: 24px;
margin-top: 3px;
margin-bottom: 2px;
vertical-align: middle;
}
</style>
更多推荐
已为社区贡献2条内容
所有评论(0)