vue底部跳转_h5之vue自定义底部导航栏

本文通过示例代码展示了如何在 Vue 中创建一个自定义的底部导航栏,包括组件 Item 和 Tabbar 的实现,以及点击跳转和选中状态的处理。组件使用了 props 和 computed 属性来实现选中效果,并利用 $router.push 进行页面切换。
摘要由CSDN通过智能技术生成

代码

Item.vue

export default{

name: 'Item',

props:{

txt:{

type:String

},

page:{

type:String

},

sel:{

type:String

}

},

computed:{

bol: function(){

if(this.sel == this.page){

return true;

}

return false;

}

},

methods:{

changePage:function(){

//点击跳转对应的页面

this.$router.push('/'+this.page);

this.$emit('change',this.page)

}

}

}

.itemWarp{

flex-grow: 1;

display: flex;

align-items: center;

justify-content: center;

flex-direction: column;

}

.itemWarp span{

font-size: 12px;

}

Tabbar.vue

import Item from './Item.vue'

export default{

components:{

Item

},

data:function(){

return{

selected:'skin',

tabbarDes:[

{

txt:'账号',

page:'account',

normalImg:require('../assets/images/1.jpg'),

activeImg:require('../assets/images/2.jpg')

},

{

txt:'设置',

page:'setup',

normalImg:require('../assets/images/3.jpg'),

activeImg:require('../assets/images/4.jpg')

}

]

}

},

methods:{

getVal:function(res){

this.selected = res;

}

}

}

.warp{

width: 100%;

border-top: 1px solid #eee;

background: #fff;

display: flex;

align-items: center;

justify-content: space-around;

font-size: 0;

}

.warp img{

width: 20px;

height: 20px;

}

.tabberWarp img{

margin-top: 10px;

margin-bottom: 5px;

}

.tabberWarp{

position: fixed;

bottom: 0;

left: 0;

width: 100%;

padding-bottom: 5px;

background: #fff;

}

app.vue

import Tabbar from './components/Tabbar.vue'

components:{ Tabbar },

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值