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

uniapp微信小程序底部動(dòng)態(tài)tabBar的解決方案(自定義tabBar導(dǎo)航)

 更新時(shí)間:2022年04月22日 09:09:25   作者:Terminal丶句點(diǎn)  
tabBar如果應(yīng)用是一個(gè)多tab應(yīng)用,可以通過tabBar配置項(xiàng)指定tab欄的表現(xiàn),以及tab切換時(shí)顯示的對(duì)應(yīng)頁,下面這篇文章主要給大家介紹了關(guān)于uniapp微信小程序底部動(dòng)態(tài)tabBar的解決方案,需要的朋友可以參考下

需求

分包中如果有6個(gè)頁面A B C D E F,這6個(gè)頁面可以作為tabbar頁面進(jìn)行展示,具體配置通過后臺(tái)接口返回(頁面數(shù)量限制依然存在 2 - 5),比如后臺(tái)配置A B C D E這個(gè)5個(gè)頁面為tabbar頁面,那么A B C D E將作為tab頁展示,跳轉(zhuǎn)方式也是tab方式跳轉(zhuǎn),跳轉(zhuǎn)到F頁面為普通navigate跳轉(zhuǎn)。
這將解決 多商家底部tab配置問題,可以讓商家自己配置小程序tab頁的展示模式。

實(shí)現(xiàn)原理

1.自定義底部導(dǎo)航,數(shù)據(jù)通過接口獲取

2.將需要配置成tab的頁面內(nèi)容抽離成為組件,對(duì)應(yīng)頁面直接引用組件,tab頁面引用全部組件,并根據(jù)當(dāng)前tab頁對(duì)應(yīng)的組件頁面路徑分別展示。

3.解決組件的生命周期問題。

實(shí)現(xiàn)

頁面整體結(jié)構(gòu)

pages.json頁面配置好5個(gè)tabbar模板頁面,并且使用了easycom模式,自動(dòng)加載組件

 "easycom": {
    "^u-(.*)": "@/uview-ui/components/u-$1/u-$1.vue",
    "^sww-(.*)": "@/components/sww-$1/sww-$1.vue"
  },
"tabBar": {
    "color": "#7A7E83",
    "selectedColor": "#3cc51f",
    "borderStyle": "black",
    "backgroundColor": "#ffffff",
    "list": [
      {
        "pagePath": "pages/index/index"
      },
      {
        "pagePath": "pages/module-page-one/index"
      },
      {
        "pagePath": "pages/module-page-two/index"
      },
      {
        "pagePath": "pages/module-page-three/index"
      },
      {
        "pagePath": "pages/module-page-four/index"
      }
    ]
  }

自定義tabbar使用的uview組件

//sww-tab-bar
<template>
  <u-tabbar v-model="current" :list="vuex_tab_bar.list" :active-color="vuex_tab_bar.activeColor"
            :inactive-color="vuex_tab_bar.inactiveColor"
            @change="onChange"></u-tabbar>
</template>
<script>
import {mapState} from 'vuex'
import {uniLinkTo} from "../../utils/uniPromise";

export default {
  data() {
    return {}
  },
  computed: {
    ...mapState(['vuex_tab_bar', 'vuex_tab_page']),
    current: {
      get(){
        return this.$store.state.vuex_tab_bar.current
      },
      set(value){
        this.$store.commit('$uStore',{name: 'vuex_tab_bar.current', value})
      }
    }
  },
  methods: {
    onChange(index) {
      uniLinkTo(this.vuex_tab_page[index], 'tab')
    }
  }
}
</script>
<style lang="scss" scoped>
	::v-deep .u-fixed-placeholder {
		opacity: 0;
	}
</style>

vuex中保存的tabbar數(shù)據(jù)格式

 vuex_tab_bar: {
            list: [],
            activeColor: '',
            inactiveColor: '',
            current: 0
        },
vuex_tab_bar_default: { //接口未獲取到數(shù)據(jù)時(shí)使用的默認(rèn)tabbar
            list: [
                {
                    iconPath: '/static/tab/home.png',
                    selectedIconPath: '/static/tab/home_fill.png',
                    text: '首頁',
                    url: '/package/index/index'
                },
                {
                    iconPath: '/static/tab/cat.png',
                    selectedIconPath: '/static/tab/cat_fill.png',
                    text: '分類',
                    url: '/package/product/category/index'
                },
                {
                    iconPath: '/static/tab/community.png',
                    selectedIconPath: '/static/tab/community_fill.png',
                    text: '鏈圈',
                    url: '/package/index/circle/index'
                },
                {
                    iconPath: '/static/tab/cart.png',
                    selectedIconPath: '/static/tab/cart_fill.png',
                    text: '購物車',
                    // url: '/package/user/order/index'
                    url: '/package/user/cart/index'
                },
                {
                    iconPath: '/static/tab/user.png',
                    selectedIconPath: '/static/tab/user_fill.png',
                    text: '我的',
                    url: '/package/user/index'
                }
            ],
            activeColor: '#e93324',
            inactiveColor: '#666666',
            current: 0
        },

上面的步驟已經(jīng)完成了自定義底部tabbar,接下來是tab頁面中使用組件的方式和tabbar數(shù)據(jù)的獲取

//這里的代碼是5個(gè)模板tab頁面的內(nèi)容,頁面引入了所有可配置成為tab的組件,js部分抽離到mixins中進(jìn)行代碼復(fù)用
<template>
  <view class="index-box">
    <block v-if="pageModuleName('/package/index/index')">
      <sww-page-home ref="modulePageRef"></sww-page-home>
    </block>
    <block v-if="pageModuleName('/package/product/category/index')">
      <sww-page-category ref="modulePageRef"></sww-page-category>
    </block>
    <block v-if="pageModuleName('/package/index/circle/index')">
      <sww-page-circle ref="modulePageRef"></sww-page-circle>
    </block>
    <block v-if="pageModuleName('/package/user/cart/index')">
      <sww-page-cart ref="modulePageRef"></sww-page-cart>
    </block>
    <block v-if="pageModuleName('/package/user/index')">
      <sww-page-user ref="modulePageRef"></sww-page-user>
    </block>
    <block v-if="pageModuleName('/package/user/order/index')">
      <sww-page-order ref="modulePageRef"></sww-page-order>
    </block>
    <sww-tab-bar ref="tabBarRef"></sww-tab-bar>
    <sww-login></sww-login>
  </view>
</template>
<script>
import {tabPage} from "../../mixins/tabPage";

export default {
  mixins: [tabPage],
  data() {
    return {
      tabIndex: 4
    }
  }
}
</script>
<style>
page {
  width: 100%;
  height: 100%;
}
.index-box {
  width: 100%;
  height: 100%;
}
</style>

// tabPagemixins
import {mapState} from 'vuex'
const App = getApp()

export const tabPage = {
    computed: {
        ...mapState(['vuex_tab_bar', 'vuex_module_page']),
        //獲取當(dāng)前tab頁要顯示的頁面組件
        pageModuleName(name) {
            return (name) => {
                if (this.vuex_tab_bar.list.length > 0) {
                	//這里的url是后臺(tái)用戶配置的頁面路徑,此路徑是分包中實(shí)際存在的頁面路徑,比如A頁面要配置成為tab,那么就將A頁面內(nèi)容抽離成組件,后臺(tái)配置此頁面為tab,只需將A頁面的實(shí)際路徑進(jìn)行配置即可
                    return this.vuex_tab_bar.list[this.tabIndex].url === name
                } else {
                    return false
                }
            }
        }
    },
    onLoad: function () {
        this.$nextTick(() => {
            try {
                if (this.vuex_tab_bar.list.length === 0) {
                   App.loadTabBarList().then(() => {
                       this.$refs.modulePageRef.$onLoad()
                   })
                } else {
                    this.$refs.modulePageRef.$onLoad()
                }
            } catch (e) {

            }
        })
    },
    // isoH5在onshow時(shí)要重置分享
    onShow: function () {
        this.$nextTick(() => {
            try {
                this.$refs.modulePageRef.$onShow()
            } catch (e) {

            }
        })
    },
    onHide: function () {
        this.$nextTick(() => {
            try {
                this.$refs.modulePageRef.$onHide()
            } catch (e) {

            }
        })
    },
    onPullDownRefresh: function () {
        try {
            this.$refs.modulePageRef.$onPullDownRefresh()
        } catch (e) {

        }
    },
    onReachBottom: function () {
        try {
            this.$refs.modulePageRef.$onReachBottom()
        } catch (e) {

        }
    },
    // 微信小程序分享(好友)
    onShareAppMessage: function () {
        return this.$refs.modulePageRef.getShareAppMessage()
    },
    // 微信小程序分享(朋友圈)
    onShareTimeline: function () {
        return this.$refs.modulePageRef.getShareTimeline()
    }
}

總結(jié)

到此這篇關(guān)于uniapp微信小程序底部動(dòng)態(tài)tabBar的文章就介紹到這了,更多相關(guān)小程序自定義tabBar底部導(dǎo)航內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • JavaScript中按位“異或”運(yùn)算符使用介紹

    JavaScript中按位“異或”運(yùn)算符使用介紹

    按位“異或”運(yùn)算符 (^)是對(duì)兩個(gè)表達(dá)式執(zhí)行按位異或,下面為大家介紹下其具體的使用方法
    2014-03-03
  • JavaScript電話號(hào)碼格式化的多種實(shí)現(xiàn)方式

    JavaScript電話號(hào)碼格式化的多種實(shí)現(xiàn)方式

    本文希望通過一道簡單的題目,讓剛接觸JavaScript的新手們了解一個(gè)合格的前端程序員需要具備哪些素質(zhì),文章給大家介紹了JavaScript電話號(hào)碼格式化的多種實(shí)現(xiàn)方式,感興趣的小伙伴跟著小編一起來看看吧
    2024-11-11
  • IE6下javasc#ipt:void(0) 無效的解決方法

    IE6下javasc#ipt:void(0) 無效的解決方法

    本篇文章主要是對(duì)IE6下javasc#ipt:void(0) 無效的解決方法進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助
    2013-12-12
  • Javascript 獲取滾動(dòng)條位置等信息的函數(shù)

    Javascript 獲取滾動(dòng)條位置等信息的函數(shù)

    有時(shí)為了準(zhǔn)確定位一個(gè)元素,我們需要獲取滾動(dòng)條的位置,這種需求經(jīng)常出現(xiàn)在 tooltip 和 拖放等應(yīng)用中,其實(shí)這個(gè)技術(shù)很簡單,關(guān)鍵是要考慮瀏覽器的兼容性,本文就是介紹這一問題的解決方法。
    2009-09-09
  • video.js 實(shí)現(xiàn)視頻只能后退不能快進(jìn)的思路詳解

    video.js 實(shí)現(xiàn)視頻只能后退不能快進(jìn)的思路詳解

    這篇文章主要介紹了video.js 實(shí)現(xiàn)視頻只能后退不能快進(jìn)的思路詳解,主要思路是點(diǎn)擊進(jìn)度條需要獲取拖動(dòng)前的時(shí)間點(diǎn),具體實(shí)例代碼大家跟隨小編一起看看吧
    2018-08-08
  • 前端實(shí)現(xiàn)HTML網(wǎng)頁轉(zhuǎn)PDF并導(dǎo)出

    前端實(shí)現(xiàn)HTML網(wǎng)頁轉(zhuǎn)PDF并導(dǎo)出

    這篇文章主要為大家詳細(xì)介紹了前端如何通過html2canvas和jsPDF實(shí)現(xiàn)HTML網(wǎng)頁轉(zhuǎn)PDF并導(dǎo)出,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考一下
    2025-01-01
  • 如何利用Javascript生成平滑曲線詳解

    如何利用Javascript生成平滑曲線詳解

    相信大家都遇到過,在各種圖表框架中經(jīng)常會(huì)有將一段折線平滑的需求,不僅能給用戶帶來一種柔和的感覺,還能美化界面,讓折線看起來沒那么生硬,這篇文章主要給大家介紹了關(guān)于如何利用Javascript生成平滑曲線的相關(guān)資料,需要的朋友可以參考下
    2021-07-07
  • js獲取內(nèi)聯(lián)樣式的方法

    js獲取內(nèi)聯(lián)樣式的方法

    這篇文章主要介紹了js獲取內(nèi)聯(lián)樣式的方法,針對(duì)標(biāo)準(zhǔn)瀏覽器與IE瀏覽器進(jìn)行不同的判斷與獲取,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • 基于Two.js實(shí)現(xiàn)星球環(huán)繞動(dòng)畫效果的示例

    基于Two.js實(shí)現(xiàn)星球環(huán)繞動(dòng)畫效果的示例

    本篇文章主要介紹了基于Two.js實(shí)現(xiàn)=星球環(huán)繞動(dòng)畫效果的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • JS變量提升原理與用法實(shí)例淺析

    JS變量提升原理與用法實(shí)例淺析

    這篇文章主要介紹了JS變量提升,結(jié)合實(shí)例形式分析了JS變量提升基本概念、功能、原理、用法及相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2020-05-05

最新評(píng)論

诸城市| 政和县| 英吉沙县| 清河县| 吐鲁番市| 乌拉特前旗| 托里县| 双城市| 襄城县| 织金县| 平顶山市| 寿光市| 张家港市| 武强县| 那曲县| 天水市| 精河县| 宣化县| 巫山县| 乐平市| 九台市| 泸西县| 宣城市| 磐石市| 独山县| 莒南县| 繁峙县| 许昌市| 吉木萨尔县| 绥芬河市| 紫阳县| 海伦市| 武汉市| 碌曲县| 崇明县| 平顶山市| 齐河县| 衡南县| 临高县| 巴彦县| 陵川县|