最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

uni-app自定義導(dǎo)航欄按鈕|uniapp仿微信頂部導(dǎo)航條功能

 更新時(shí)間:2019年11月12日 08:42:19   作者:xiaoyan2017  
這篇文章主要介紹了uni-app自定義導(dǎo)航欄按鈕|uniapp仿微信頂部導(dǎo)航條,需要的朋友可以參考下

最近一直在學(xué)習(xí)uni-app開發(fā),由于uniapp是基于vue.js技術(shù)開發(fā)的,只要你熟悉vue,基本上很快就能上手了。

在開發(fā)中發(fā)現(xiàn)uni-app原生導(dǎo)航欄也能實(shí)現(xiàn)一些頂部自定義按鈕+搜索框,只需在page.json里面做一些配置即可。設(shè)置app-plus,配置編譯到App平臺(tái)的特定樣式。dcloud平臺(tái)對(duì)app-plus做了詳細(xì)說(shuō)明:app-plus配置,需注意 目前暫支持H5、App端,不支持小程序。

在page.json里配置app-plus即可

{
 "path": "pages/ucenter/index",
 "style": {
  "navigationBarTitleText": "我的",
  "app-plus": {
   "titleNView": {
    "buttons": [
     {
      "text": "\ue670",
      "fontSrc": "/static/iconfont.ttf",
      "fontSize": "22px",
      "float": "left"
     },
     {
      "text": "\ue62c",
      "fontSrc": "/static/iconfont.ttf",
      "fontSize": "22px"

     }
    ],
    "searchInput":{
     ...
    }
   }
  }
 }
},

對(duì)于如何監(jiān)聽按鈕、輸入框事件,uni-app給出了相應(yīng)API,只需把onNavigationBarButtonTap和onNavigationBarSearchInputChanged,寫在響應(yīng)的頁(yè)面中即可。

那如何可以實(shí)現(xiàn)像京東、淘寶、微信頂部導(dǎo)航欄,如加入城市定位、搜索、自定圖片/圖標(biāo)、圓點(diǎn)提示。。。

上面的方法是可以滿足一般項(xiàng)目需求,但是在小程序里則失效了,而且一些復(fù)雜的導(dǎo)航欄就不能很好兼顧,這時(shí)只能尋求其它替代方法了

將navigationStyle設(shè)為custom或titleNView設(shè)為false時(shí),原生導(dǎo)航欄不顯示,這時(shí)就能自定義導(dǎo)航欄

"globalStyle": {"navigationStyle": "custom"}

下面是簡(jiǎn)單測(cè)試實(shí)例:

這里要注意的是,H5、小程序、App端狀態(tài)欄都不一樣,需要重新計(jì)算處理,我這里已經(jīng)處理好了,可直接使用,在App.vue里面設(shè)置即可

onLaunch: function() {
 uni.getSystemInfo({
  success:function(e){
   Vue.prototype.statusBar = e.statusBarHeight
   // #ifndef MP
   if(e.platform == 'android') {
    Vue.prototype.customBar = e.statusBarHeight + 50
   }else {
    Vue.prototype.customBar = e.statusBarHeight + 45
   }
   // #endif
   
   // #ifdef MP-WEIXIN
   let custom = wx.getMenuButtonBoundingClientRect()
   Vue.prototype.customBar = custom.bottom + custom.top - e.statusBarHeight
   // #endif
   
   // #ifdef MP-ALIPAY
   Vue.prototype.customBar = e.statusBarHeight + e.titleBarHeight
   // #endif
  }
 })
},

嘖嘖,看下面的效果,是不是覺得很眼熟,沒錯(cuò),就是基于uni-app簡(jiǎn)單的實(shí)現(xiàn)了一個(gè)仿微信頂部導(dǎo)航條

頂部的圖標(biāo)使用iconfont字體圖標(biāo)、另外還可自定傳入圖片

<header-bar :isBack="false" title="標(biāo)題信息" titleTintColor="#fff">
 <text slot="back" class="uni_btnIco iconfont icon-arrL"></text>
 <text slot="iconfont" class="uni_btnIco iconfont icon-search" @tap="aaa"></text>
 <text slot="iconfont" class="uni_btnIco iconfont icon-tianjia" @tap="bbb"></text>
 <!-- <text slot="string" class="uni_btnString" @tap="ccc">添加好友</text> -->
 <image slot="image" class="uni_btnImage" src="../../static/logo.png" mode="widthFix" @tap="ddd"></image>
</header-bar>

<header-bar :isBack="true" titleTintColor="#fff" :bgColor="{'background-image': 'linear-gradient(45deg, #007AFF 10%, #005cbf)'}" search>
 <text slot="back" class="uni_btnIco iconfont icon-arrL"></text>
 <text slot="iconfont" class="uni_btnIco iconfont icon-choose03" @tap="aaa"></text>
 <image slot="image" class="uni_btnImage" src="../../static/logo.png" mode="widthFix" @tap="ddd"></image>
</header-bar>

<header-bar :isBack="true" title="我的" titleTintColor="#fff" :bgColor="{background: '#353535'}">
 <text slot="back" class="uni_btnIco iconfont icon-close"></text>
 <text slot="iconfont" class="uni_btnIco iconfont icon-search"></text>
 <text slot="string" class="uni_btnString" style="color: #2B9939;">添加好友</text>
</header-bar>

支持傳入的屬性,另外還用到了vue插槽slot

/***
  isBack    是否返回按鈕
  title    標(biāo)題
  titleTintColor  標(biāo)題顏色
  bgColor    背景
  center    標(biāo)題居中
  search    搜索條
  searchRadius  圓形搜索條
  fixed    是否固定
*/
<template>
 <view class="uni_topbar" :style="style">
  <view class="inner flexbox flex_alignc" :class="[fixed ? 'fixed' : '']" :style="[{'height': customBarH + 'px', 'padding-top': statusBarH + 'px', 'color': titleTintColor}, bgColor]">
   <!-- 返回 -->
   <!-- <text class="uni_icoBack iconfont icon-arrL" v-if="isBack" @tap="goBack"></text> -->
   <view v-if="isBack" @tap="goBack">
    <slot name="back"></slot>
   </view>
   <slot name="headerL"></slot>
   <!-- 標(biāo)題 -->
   <!-- #ifndef MP -->
   <view class="flex1" v-if="!search && center"></view>
   <!-- #endif -->
   <view class="uni_title flex1" :class="[center ? 'uni_titleCenter' : '']" :style="[isBack ? {'font-size': '32upx', 'padding-left': '0'} : '']" v-if="!search && title">
    {{title}}
   </view>
   <view class="uni_search flex1" :class="[searchRadius ? 'uni_searchRadius' : '']" v-if="search"> />
    <input class="uni_searchIpt flex1" type="text" placeholder="搜索" placeholder-style="color: rgba(255,255,255,.5);" />
   </view>
   <!-- 右側(cè) -->
   <view class="uni_headerRight flexbox flex_row flex_alignc">
    <slot name="iconfont"></slot>
    <slot name="string"></slot>
    <slot name="image"></slot>
   </view>
  </view>
 </view>
</template>

<script>
 export default {
  data() {
   return {
    statusBarH: this.statusBar,
    customBarH: this.customBar
   }
  },
  props: {
   isBack: { type: [Boolean, String], default: true },
   title: { type: String, default: '' },
   titleTintColor: { type: String, default: '#fff' },
   bgColor: Object,
   center: { type: [Boolean, String], default: false },
   search: { type: [Boolean, String], default: false },
   searchRadius: { type: [Boolean, String], default: false },
   fixed: { type: [Boolean, String], default: false },
  },
  computed: {
   style() {
    let _style = `height: ${this.customBarH}px;`
    return _style
   }
  },
  methods: {
   goBack() {
    uni.navigateBack()
   }
  }
 }
</script>

最后附上一個(gè)基于ReactNative實(shí)現(xiàn)的自定義導(dǎo)航條的聊天室項(xiàng)目

http://www.fzitv.net/article/174036.htm

總結(jié)

以上所述是小編給大家介紹的uni-app自定義導(dǎo)航欄按鈕|uniapp仿微信頂部導(dǎo)航條,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • 詳解vue中的動(dòng)態(tài)組件component和keep-alive

    詳解vue中的動(dòng)態(tài)組件component和keep-alive

    這篇文章主要介紹了詳解vue中的動(dòng)態(tài)組件component和keep-alive的相關(guān)資料,這大家需要注意include屬性和exclude屬性只能用一個(gè),不能同時(shí)使用,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2023-11-11
  • Vue替代marquee標(biāo)簽超出寬度文字橫向滾動(dòng)效果

    Vue替代marquee標(biāo)簽超出寬度文字橫向滾動(dòng)效果

    這篇文章主要介紹了Vue替代marquee標(biāo)簽超出寬度文字橫向滾動(dòng)效果,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • vue中v-for和v-if一起使用之使用compute的示例代碼

    vue中v-for和v-if一起使用之使用compute的示例代碼

    這篇文章主要介紹了vue中v-for和v-if一起使用之使用compute的相關(guān)知識(shí),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • Vue3響應(yīng)式對(duì)象是如何實(shí)現(xiàn)的(1)

    Vue3響應(yīng)式對(duì)象是如何實(shí)現(xiàn)的(1)

    這篇文章主要介紹了Vue3響應(yīng)式對(duì)象是如何實(shí)現(xiàn)的,文章圍繞主題展開詳細(xì)的內(nèi)容介紹具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-08-08
  • vue element動(dòng)態(tài)渲染、移除表單并添加驗(yàn)證的實(shí)現(xiàn)

    vue element動(dòng)態(tài)渲染、移除表單并添加驗(yàn)證的實(shí)現(xiàn)

    這篇文章主要介紹了vue element動(dòng)態(tài)渲染、移除表單并添加驗(yàn)證的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01
  • vue使用eventBus遇到數(shù)據(jù)不更新的問(wèn)題及解決

    vue使用eventBus遇到數(shù)據(jù)不更新的問(wèn)題及解決

    這篇文章主要介紹了vue使用eventBus遇到數(shù)據(jù)不更新的問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Vue的diff算法原理你真的了解嗎

    Vue的diff算法原理你真的了解嗎

    這篇文章主要為大家詳細(xì)介紹了Vue的diff算法原理,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-03-03
  • 一篇帶你搞懂Vue中的自定義指令

    一篇帶你搞懂Vue中的自定義指令

    自定義指令,是Vue提供的一種擴(kuò)展和定制的機(jī)制,使開發(fā)者能夠在組件中直接操作DOM、處理事件、添加樣式等,并提供了與第三方庫(kù)集成的方式,定義指令使得Vue在處理交互和DOM操作時(shí)更加靈活和強(qiáng)大,本文將帶大家搞懂Vue中的自定義指令,需要的朋友可以參考下
    2023-07-07
  • 基于Vue結(jié)合ElementUI的換膚解決方案

    基于Vue結(jié)合ElementUI的換膚解決方案

    本文將介紹幾種基于Vue、Element-UI的換膚實(shí)現(xiàn)方案,力爭(zhēng)通俗易懂,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Vue.js 利用v-for中的index值實(shí)現(xiàn)隔行變色

    Vue.js 利用v-for中的index值實(shí)現(xiàn)隔行變色

    這篇文章主要介紹了Vue.js 利用v-for中的index值實(shí)現(xiàn)隔行變色效果,首先定義好樣式,利用v-for中的index值,然后綁定樣式來(lái)實(shí)現(xiàn)隔行變色,需要的朋友可以參考下
    2018-08-08

最新評(píng)論

晋城| 舞阳县| 德化县| 东阳市| 田林县| 招远市| 申扎县| 奉化市| 辰溪县| 定安县| 比如县| 安新县| 巢湖市| 西平县| 常德市| 商丘市| 天峨县| 安乡县| 安徽省| 柳河县| 新竹市| 时尚| 越西县| 布尔津县| 深泽县| 平谷区| 象州县| 察隅县| 余干县| 乡宁县| 中方县| 太白县| 广宗县| 凤阳县| 南丰县| 望城县| 五华县| 海城市| 阿城市| 阿克| 石林|