VUE之小米商城(一)之固定底部导航条
学vue不久,打算做一个项目,边做边记录,记录自己遇到的困难。
首先遇到的就是第一个底部导航条的问题,因为不想用position:fixed;bottom:0;所以初步接触了一点flex布局,要学习flex可以去看看阮一峰了,挺不错的,阮一峰flex布局,闲话少说,先上效果图吧
App.vue:(这里把底部导航条封装成一个组件BottomNav,router-view为路由到index.vue页面 )
<template>
<div style=" display: flex;flex-direction: column;min-height: 100vh;">
<router-view></router-view>
<BottomNav></BottomNav>
</div>
</template>
<script>
import BottomNav from './components/BottomNav'
export default {
components:{
BottomNav
}
}
</script>
<style>
</style>
index.vue(max-height: 92vh;设置主内容区为92%屏幕与下方的BottomNav的8% 加起来为100%,然后再通过后面的设置滚动条就可以得到所想要的结果overflow-y: scroll;)
<template>
<div style="max-height: 92vh;overflow-y: scroll;flex: 1;">
index<br/>
index<br/>
index<br/>
index<br/> index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/> index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/> index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/> index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/> index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/> index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
index<br/>
</div>
</template>
<script>
export default {
}
</script>
<style>
</style>
BottomNav.vue
<template>
<div class="navigation">
<div class="nav"><img class="navIcon" src="../../static/image/homeOn.png"/>首页</div>
<div class="nav"><img class="navIcon" src="../../static/image/categoryOff.png"/>分类</div>
<div class="nav"><img class="navIcon" src="../../static/image/discoverOff.png"/>发现</div>
<div class="nav"><img class="navIcon" src="../../static/image/cartOff.png"/>购物车</div>
<div class="nav"><img class="navIcon" src="../../static/image/meOff.png"/>我的</div>
</div>
</template>
<script>
export default {}
</script>
<style>
.navigation{
display:flex;/*设置五个导航条的内容由列排列变为行排列*/
height: 8vh ;
font-size: 0.7rem;
}
.nav{
display: flex;/*这个和下面的 flex-direction属性设置将图片与文字平行排布*/
flex-direction: column;
flex: 1;/*设置五个导航条的内容等分*/
margin: 0.5rem 0 0 1rem;
line-height: 1.2rem;
}
.navIcon{
width: 1.3rem;
height: 1.3rem;
}
</style>