vue写一个底部导航栏

在这里插入图片描述
实现的最终结果如上图。

<template>
	<div id="app">
	  <div id="router-view">
		  <router-view/>
	  </div>
		
		<div id="nav">
			<div><router-link to="/">Home1</router-link></div>
			<div><router-link to="/shop">Shop</router-link></div>
			<div><router-link to="/mine">Mine</router-link></div>
			<div><router-link to="/search">search</router-link></div>
		</div>
	</div>
</template>

由于<template>标签下只能有一个子分支,所以我们用<div>将其圈起来.
其下有两个子分支,一个是router-view,用来显示不同的页面,另一个是nav,用来作为底部导航栏。
我们将下面的4个部件也都分别用<div>圈起来,为以后在里面加入图片等元素做准备。

然后开始css。

<style lang="less">
	
	*{
		border: 0;
		margin: 0;
		padding: 0;
	}
	#nav{
		width: 100%;
		height: 50px;
		display: flex;
		bottom: 0;
		position: fixed;
		div{
			flex:1;
			background-color: lightblue;
			margin: 1px;
			text-align: center;
			line-height: 50px;
		}
	}
	#router-view{
		background-color: pink;
		height: calc(100vh - 50px);
		overflow: auto;
	}
</style>

这里面,我们将navposition设置为fixed,使其固定。display设置为flex,为弹性布局,bottom设置为0,使其在底部。
由于仅仅做此设置,会使底部导航栏挡住router-view的正常显示,所以我们要获取当前页面的总像素的高,用calc(100vh)获取,减掉我们设置的导航栏的高度50px,就不会影响router-view的正常显示了。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用vue-router和vue-awesome-swiper第三方库来实现一个带有底部导航栏的手机app界面。 首先,在main.js中导入vue-router和vue-awesome-swiper: ``` import Vue from 'vue' import VueRouter from 'vue-router' import VueAwesomeSwiper from 'vue-awesome-swiper' import 'swiper/dist/css/swiper.css' Vue.use(VueRouter) Vue.use(VueAwesomeSwiper) ``` 然后,创建一个App.vue组件,包含底部导航栏和路由视图: ``` <template> <div id="app"> <div class="main"> <router-view></router-view> </div> <div class="tabbar"> <router-link to="/" class="tabbar-item"> <i class="iconfont icon-home"></i> <span>首页</span> </router-link> <router-link to="/category" class="tabbar-item"> <i class="iconfont icon-category"></i> <span>分类</span> </router-link> <router-link to="/cart" class="tabbar-item"> <i class="iconfont icon-cart"></i> <span>购物车</span> </router-link> <router-link to="/profile" class="tabbar-item"> <i class="iconfont icon-profile"></i> <span>我的</span> </router-link> </div> </div> </template> <script> export default { name: 'App' } </script> <style> .tabbar { display: flex; position: fixed; bottom: 0; left: 0; width: 100%; background-color: #fff; box-shadow: 0 -2px 4px rgba(0,0,0,.15); z-index: 99; } .tabbar-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #999; font-size: 12px; text-decoration: none; } .tabbar-item.active { color: #33a3f4; } .tabbar-item i { font-size: 20px; margin-bottom: 2px; } .main { margin-bottom: 50px; } </style> ``` 在路由配置文件中,定义每个路由对应的组件: ``` import Vue from 'vue' import Router from 'vue-router' import Home from './views/Home.vue' import Category from './views/Category.vue' import Cart from './views/Cart.vue' import Profile from './views/Profile.vue' Vue.use(Router) export default new Router({ routes: [ { path: '/', component: Home }, { path: '/category', component: Category }, { path: '/cart', component: Cart }, { path: '/profile', component: Profile } ] }) ``` 最后,在各个页面组件中,使用vue-awesome-swiper实现轮播图等效果。 以上就是一个简单的带有底部导航栏的手机app界面的实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值