<template>
<view class="tabbarBox">
<view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
<view class="tabbar-item" v-for="(item, index) in list" :key="index" @click="tabbarChange(item.path)">
<image class="item-img" :src="item.icon_a" v-if="current == index"></image>
<image class="item-img" :src="item.icon" v-else></image>
<view class="item-name" :class="{'tabbarActive': current == index}"
v-if="item.text">
{{item.text}}
</view>
</view>
</view>
</view>
</template>
<script>
export default {
props: {
current: 0
},
data() {
return {
paddingBottomHeight: 0, //苹果X以上手机底部适配高度
list: [{
text: '首页',
icon: '../../../static/image/shop/user-order/Frame 31@2x.png', //未选中图标
icon_a: '../../../static/image/shop/user-order/Frame 31@2x.png', //选中图片
path: "", //页面路径
}, {
text: '分类',
icon: '../../../static/image/shop/user-order/Frame.png', //未选中图标
icon_a: '../../../static/image/shop/user-order/Frame.png', //选中图片
path: "",
}, {
text: '购物车',
icon: '../../../static/image/shop/user-order/Frame@2x(1).png', //未选中图标
icon_a: '../../../static/image/shop/user-order/Frame@2x(1).png', //选中图片
path: '',
}, {
text: '订单',
icon: '../../../static/image/shop/user-order/Frame@2x(2).png', //未选中图标
icon_a: '../../../static/image/shop/user-order/Frame@2x(2).png', //选中图片
path: "",
}, ]
};
},
created() {
let that = this;
uni.getSystemInfo({
success: function(res) {
let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
model.forEach(item => {
//适配iphoneX以上的底部,给tabbar一定高度的padding-bottom
if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
that.paddingBottomHeight = 40;
}
})
}
});
},
methods: {
tabbarChange(path) {
uni.navigateTo({
url:path
})
}
}
};
</script>
<style lang="less" scoped>
.tabbarActive {
color: #0EB87E !important;
}
.tabbarBox {
position: fixed;
bottom: 0;
left: 0;
right: 0;
// background-image: url(../../static/image/index/tabsBG.png);
// background-color: #096;
// background-size: 100% 160rpx;
// background-repeat: no-repeat;
// height: 160rpx;
// width: 750rpx;
height: 120rpx;
background: #FFFFFF;
border-radius: 0rpx 0rpx 0rpx 0rpx;
border: 2rpx solid #F0F0F0;
.tabbar {
box-sizing: border-box;
// background-color: #ffffff;
position: fixed;
bottom: 10rpx;
display: flex;
justify-content: space-around;
align-items: center;
width: 100%;
height: 100rpx;
margin-left: -10rpx;
.tabbar-item {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100rpx;
.item-img {
width: 44rpx;
height: 44rpx;
margin-bottom: 4rpx;
}
.item-name {
// width: 48rpx;
height: 24rpx;
margin-left: 0rpx;
margin-top: 12rpx;
font-family: PingFang SC, PingFang SC;
font-weight: 500;
font-size: 24rpx;
color: #8B8B8B;
line-height: 24rpx;
text-align: center;
font-style: normal;
text-transform: none;
}
}
}
}
</style>
上面是组件
效果图:
引入部分
<template>
<view class="content">
<view-tabbar :current="1"></view-tabbar> //:current="1" 当前页面是第几个
</view>
</template>
<script>
import Tabbar from '@/components/tabbar/tabbar.vue'
export default {
components: {
'view-tabbar': Tabbar
},
data() {
return {
}
},
onLoad() {
},
methods: {
}
}
</script>
<style>
</style>