vue router 底部导航栏功能(不使用icon)

<template>
	<div class="footer">
		<div v-for='(item,index) of items' :class='[item.type,{selectedTab:index === indexType}]' @click="$router.push(item.push)">
			<img :src="index===indexType?item.iconSelect:item.icon">
			<p :class="['colorChange',{selectedTab:index===indexType}]">{{item.name}}</p>
		</div>

	</div>
</template>

js 注意的是,引用图片的时候,有些不加require,图片显示不出来

export default {
		props: ['indexType'],
		data() {
			return {
				items: [{
						type: "Home",
						name: "首页",
						push: "/Home",
						icon: require("../img/index.png"),
						iconSelect: require("../img/index_selected.png")
					},
					{
						cla: "Member",
						name: "社区",
						push: "/Member",
						icon: require("../img/wallet.png"),
						iconSelect: require("../img/wallet_selected.png")
					},
					{
						cla: "Me",
						name: "我的",
						push: "/Me",
						icon: require("../img/mine.png"),
						iconSelect: require("../img/mine_selected.png")
					}
				]
			}
		}
	}

css样式

<style lang="scss" scoped>
	$browser-default-font-size: 37.5px !default; //变量的值可以根据自己需求定义
	@function pxTorem($px) {
		//$px为需要转换的字号
		@return $px/$browser-default-font-size*1rem;
	}
	
	p {
		margin: 0;
		padding: 0;
	}
	
	.footer {
		display: flex;
		position: absolute;
		left: 0;
		bottom: 0;
		box-sizing: border-box;
		padding-top: pxTorem(5px);
		border-top: pxTorem(1px) solid #dfdfdf;
		width: 100%;
		div {
			flex: 1;
			-webkit-box-orient: vertical;
			font-size: pxTorem(16px);
			text-align: center;
			img {
				width: pxTorem(45px);
				height: pxTorem(45px);
				margin-top: pxTorem(10px);
			}
			p {
				color: #9f9f9f;
			}
		}
		.selectedTab {
			color: #ac1832;
		}
	}
</style>

使用时

<template>
	<div class="home">
        //使用
		<tabs :indexType="0"></tabs>
	</div>
</template>

<script>
	import tabs from '@/components/tab'
	export default {
		components: {
			tabs
		}
	}
</script>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值