这篇文章主要介绍了vue自定义底部导航栏Tabbar的实现代码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
如图所示,要完成类似的一个底部导航切换。
首先。我们需要分为5个大的VUE文件。可以根据自己的习惯来放在不同的位置。
我将5个主要的vue文件放在了5个不同的文件夹
然后,在components文件夹里新建Tabbar.vue/以及Item.vue文件
Item.vue文件如下
<div class="itemWarp flex_mid"> <span> </span><span> </span><span></span></div> .itemWarp{ flex-grow: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; } .itemWarp span{ font-size: 12px; }
Tabbar.vue文件如下
<div class="tabberWarp"> <div class="warp"> </div></div> .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; }
Tabbar.vue文件和Item.vue的关系为父子关系.
Tabbar.vue组件 通过v-for循环tabbarDes里面的数据.再通过 props 向下传递数据给子组件.Item.vue能接受到父组件传递的数据.
Item.vue组件绑定点击事件.
this.$router.push('/'+this.page);为跳转到对应的page
this.$emit('change',this.page)
为使用$emit 触发父组件的自定义事件 change,将this.page作为参数传递到父组件中.父组件点击获取到传递过来的参数.再通过props传递给item.vue.在computed计算属性中.返回不同的布尔值.来做底部图片的显示隐藏.
最后仅需要在App.来源gaodaimacom搞#^代%!码网vue中引入Tabbar组件即可.
<div id="app"> <div class="empty"></div></div>
总结
以上所述是小编给大家介绍的vue自定义底部导航栏Tabbar的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对gaodaima搞代码网网站的支持!
以上就是vue自定义底部导航栏Tabbar的实现代码的详细内容,更多请关注gaodaima搞代码网其它相关文章!