詳解vue.js移動端導航navigationbar的封裝
有幾天沒更新了,這幾天上海天氣比較熱,天氣一熱就懶得寫了。今天感覺還好,就寫下導航部分的封裝吧。
關于環(huán)境搭建和底部tabbar的封裝請參考前面的兩篇文章
web app和移動端原生app的構(gòu)架方式不一樣的,頁面的切換是對整個頁面的重新渲染。所以我們每個頁面都有自己的導航條。
下面簡單封裝下導航條
html部分
此處寫的導航的三個部分,分別是左邊div、中間的title部分div、右邊div。代碼如下
<template> <header class="m-header" :class="{'is-bg-red':bgRed, 'is-fixed':fixed}"> <div class="leftItem"><slot name="left"></slot></div> <div class="m-header-title" v-text="title"></div> <div class="rightItem"><slot name="right"></slot></div> </header> </template>
js部分代碼
此處向父類暴露了3個屬性,分別是傳入title的字符串和背景是否為紅色,已經(jīng)是否固定在頂部(默認是固定在頂部)。具體代碼如下
<script type="text/ecmascript-6"> export default{ props: { title: { type: String, default: '' }, bgRed: { type: Boolean, default: false }, fixed: { type: Boolean, default: true } } } </script>
stylus部分代碼如下
<style scoped lang="stylus" rel="stylesheet/stylus"> .m-header display flex flex-direction row align-items center height 64px background-color white border-bottom 1px solid #e5e5e5 .leftItem margin-top 24px width 60px height 40px a display block text-decoration none color #333 font-size 16px img padding 10px 10px width 24px height 24px .m-header-title width 100% height 44px margin-top 24px line-height 44px font-size $font-size-nav-title color $color-nav-item display flex justify-content center font-size 18px color #333 .rightItem margin-top 24px width 60px height 40px a display block text-decoration none color #333 font-size 16px img padding 9px 8px width 24px height 24px &.is-fixed position fixed left 0px right 0px top 0px z-index 9 &.is-bg-red background-color #ee424a .m-header-title color white .m-header-left color white .m-header-right color white </style>
封裝完畢后,我們就可以使用啦,具體使用方法如下
<template> <div> <m-header title="職位" :bgRed="isShowRefresh"> <a slot="left" v-show="false">  </a> <a slot="right">  </a> </m-header> </div> </template> <script type="text/ecmascript-6"> import MHeader from 'common/nav/navbar' export default{ data () { return { isShowRefresh: true } }, components: { MHeader } } </script>
運行效果圖如下
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- vue-router配合ElementUI實現(xiàn)導航的實例
- VueRouter導航守衛(wèi)用法詳解
- vue實現(xiàn)nav導航欄的方法
- vue實現(xiàn)導航欄效果(選中狀態(tài)刷新不消失)
- vue 掛載路由到頭部導航的方法
- vue2導航根據(jù)路由傳值,而改變導航內(nèi)容的實例
- vue-router路由與頁面間導航實例解析
- vue router仿天貓底部導航欄功能
- 詳解VueRouter進階之導航鉤子和路由元信息
- 詳解使用Vue Router導航鉤子與Vuex來實現(xiàn)后退狀態(tài)保存
- vue-router 導航鉤子的具體使用方法
- 詳解vue-router 2.0 常用基礎知識點之導航鉤子
- vue2.0實現(xiàn)導航菜單切換效果
- vue 和vue-touch 實現(xiàn)移動端左右導航效果(仿京東移動站導航)
- 非常實用的vue導航鉤子
- vue2.0 elementUI制作面包屑導航欄
相關文章
vue文件上傳Required request part ‘file‘ is&n
這篇文章主要介紹了vue文件上傳Required request part ‘file‘ is not present問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11vue elementUI select下拉框如何設置默認值
這篇文章主要介紹了vue elementUI select下拉框如何設置默認值問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10element 結(jié)合vue 在表單驗證時有值卻提示錯誤的解決辦法
這篇文章主要介紹了element 結(jié)合vue 在表單驗證下,有值卻提示錯誤的解決辦法,需要的朋友可以參考下2018-01-01vue項目watch內(nèi)的函數(shù)重復觸發(fā)問題的解決
這篇文章主要介紹了vue項目watch內(nèi)的函數(shù)重復觸發(fā)問題的兩種解決方案,幫助大家更好的理解和學習使用vue,感興趣的朋友可以了解下2021-04-04