詳解vue.js移動端導(dǎo)航navigationbar的封裝
有幾天沒更新了,這幾天上海天氣比較熱,天氣一熱就懶得寫了。今天感覺還好,就寫下導(dǎo)航部分的封裝吧。
關(guān)于環(huán)境搭建和底部tabbar的封裝請參考前面的兩篇文章
web app和移動端原生app的構(gòu)架方式不一樣的,頁面的切換是對整個頁面的重新渲染。所以我們每個頁面都有自己的導(dǎo)航條。
下面簡單封裝下導(dǎo)航條
html部分
此處寫的導(dǎo)航的三個部分,分別是左邊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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue-router配合ElementUI實現(xiàn)導(dǎo)航的實例
- VueRouter導(dǎo)航守衛(wèi)用法詳解
- vue實現(xiàn)nav導(dǎo)航欄的方法
- vue實現(xiàn)導(dǎo)航欄效果(選中狀態(tài)刷新不消失)
- vue 掛載路由到頭部導(dǎo)航的方法
- vue2導(dǎo)航根據(jù)路由傳值,而改變導(dǎo)航內(nèi)容的實例
- vue-router路由與頁面間導(dǎo)航實例解析
- vue router仿天貓底部導(dǎo)航欄功能
- 詳解VueRouter進階之導(dǎo)航鉤子和路由元信息
- 詳解使用Vue Router導(dǎo)航鉤子與Vuex來實現(xiàn)后退狀態(tài)保存
- vue-router 導(dǎo)航鉤子的具體使用方法
- 詳解vue-router 2.0 常用基礎(chǔ)知識點之導(dǎo)航鉤子
- vue2.0實現(xiàn)導(dǎo)航菜單切換效果
- vue 和vue-touch 實現(xiàn)移動端左右導(dǎo)航效果(仿京東移動站導(dǎo)航)
- 非常實用的vue導(dǎo)航鉤子
- vue2.0 elementUI制作面包屑導(dǎo)航欄
相關(guān)文章
Vue + iView實現(xiàn)Excel上傳功能的完整代碼
前一段時間項目經(jīng)歷了前端上傳文件的過程,首先進入頁面會展示默認的樣子,選中要上傳的excel文件,本文通過實例圖文相結(jié)合給大家介紹的非常詳細,需要的朋友參考下吧2021-06-06
Vue通過axios發(fā)送ajax請求基礎(chǔ)演示
這篇文章主要介紹了Vue通過axios發(fā)送ajax請求基礎(chǔ)演示,包括了axios發(fā)送簡單get請求,axios get傳參,axios發(fā)送post請求等基礎(chǔ)代碼演示需要的朋友可以參考下2023-02-02
webpack 3 + Vue2 使用dotenv配置多環(huán)境的步驟
這篇文章主要介紹了webpack 3 + Vue2 使用dotenv配置多環(huán)境,env文件在配置文件都可以用, vue頁面用的時候需要在 webpack.base.conf.js 重新配置,需要的朋友可以參考下2023-11-11

