欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 TabBar 紅點(diǎn)提醒完美解決方案

 更新時(shí)間:2024年05月15日 10:29:10   作者:飯一口口吃  
TabBar 紅點(diǎn)提醒,很多小程序都需要這個(gè)功能比如聊天小程序,電商小程序等,這時(shí)候我們需要進(jìn)行自定義 TabBar,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧

TabBar 紅點(diǎn)提醒,很多小程序都需要這個(gè)功能比如聊天小程序,電商小程序等
這時(shí)候我們需要進(jìn)行自定義 TabBar

配置信息

更改 custom 為 True 變?yōu)樽远x Tabbar

{
  "pages": [
    "pages/home/home",
    "pages/index/index",
    "pages/logs/logs"
  ],
  "window": {
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "Weixin",
    "navigationBarBackgroundColor": "#ffffff"
  },
  "componentFramework": "glass-easel",
  "sitemapLocation": "sitemap.json",
  "lazyCodeLoading": "requiredComponents",
  "usingComponents": {
    "van-button": "@vant/weapp/button/index",
    "my-numbers": "./components/numbers/numbers"
  },
  "tabBar": {
    "custom": true,
    "color": "#000000",
    "selectedColor": "#000000",
    "backgroundColor": "#ffffff",
    "list": [{
      "pagePath": "pages/home/home",
      "text": "組件"
    }, {
      "pagePath": "pages/index/index",
      "text": "接口"
    }]
  }
}

配置好后你會(huì)發(fā)現(xiàn)沒有出現(xiàn) Tabbar 這個(gè)是正常的

添加代碼文件

在跟目錄中創(chuàng)建文件夾和組件結(jié)構(gòu)

創(chuàng)建完成后可以看到這樣的界面效果

可以看到這塊是一個(gè)自定義組建,如果不能出現(xiàn)該效果,可能是因?yàn)榇a基礎(chǔ)調(diào)試庫(kù)的問(wèn)題,通常在設(shè)置自定義 TabBar 提示 TypeError,這時(shí)候需要在 詳情-》本地設(shè)置-》修改基礎(chǔ)調(diào)試庫(kù),不要使用灰度測(cè)試版本,我這里實(shí)用的是 3.4.2 版本沒有問(wèn)題

實(shí)用 Vant 組建 TabBar

引用

"usingComponents": {
  "van-tabbar": "@vant/weapp/tabbar/index",
  "van-tabbar-item": "@vant/weapp/tabbar-item/index"
}

設(shè)置 Tabbar 樣式

<!--custom-tab-bar/index.wxml-->
<van-tabbar active="{{ active }}" bind:change="onChange">
  <van-tabbar-item info="3">
    <image
      slot="icon"
      src="{{ icon.normal }}"
      mode="aspectFit"
      style="width: 30px; height: 18px;"
      />
      <image
        slot="icon-active"
        src="{{ icon.active }}"
        mode="aspectFit"
        style="width: 30px; height: 18px;"
        />
        自定義
      </van-tabbar-item>
        <van-tabbar-item icon="search">標(biāo)簽</van-tabbar-item>
        <van-tabbar-item icon="setting-o">標(biāo)簽</van-tabbar-item>
      </van-tabbar>

設(shè)置 JS

// custom-tab-bar/index.js
Component({
  /**
   * 組件的屬性列表
   */
  properties: {
  },
  /**
   * 組件的初始數(shù)據(jù)
   */
  data: {
    active: 0,
    icon: {
      normal: 'https://img.yzcdn.cn/vant/user-inactive.png',
      active: 'https://img.yzcdn.cn/vant/user-active.png',
    },
  },
  /**
   * 組件的方法列表
   */
  methods: {
    onChange(event) {
      this.setData({ active: event.detail });
    }
  }
})

共享數(shù)據(jù)給 info 屬性

創(chuàng)建 store 文件夾-》創(chuàng)建 storejs 文件

// 在這個(gè) js 文件中專門創(chuàng)建 store 對(duì)象
import {observable,action} from 'mobx-miniprogram'
export const store = observable({
  numA:1,
  numB:2,
  info:3,
  //計(jì)算屬性
  get sum(){
    return this.numA+this.numB
  },
  //action方法用來(lái)修改 store 中的值
  updateNum1:action(function(step){
    this.numA+=step
  }),
  updateNum2:action(function(step){
    this.numB+=step
  }),
})

設(shè)置 customjs 結(jié)構(gòu)

import { storeBindingsBehavior } from 'mobx-miniprogram-bindings';
import { store } from '../store/store';
Component({
  behaviors: [storeBindingsBehavior],
  properties: {},
  storeBindings: {
    store,
    fields: {
      numA: () => store.numA,
      numB: () => store.numB,
      sum: 'sum'
    },
    actions: {
      buttonTap: 'update'
    }
  },
  data: {
    info: 0,
    active: 0,
    icon: {
      normal: 'https://img.yzcdn.cn/vant/user-inactive.png',
      active: 'https://img.yzcdn.cn/vant/user-active.png',
    }
  },
  observers: {
    'sum': function(val) {
      this.setData({
        info: val
      });
    }
  },
  methods: {
    myMethod() {
      this.setData({
        info: this.data.sum
      });
    }
  }
});

設(shè)置 wxml 結(jié)構(gòu)

<!--custom-tab-bar/index.wxml-->
<van-tabbar active="{{ active }}" bind:change="onChange">
  <van-tabbar-item info="{{numA}}">
    <image
      slot="icon"
      src="{{ icon.normal }}"
      mode="aspectFit"
      style="width: 30px; height: 18px;"
    />
    <image
      slot="icon-active"
      src="{{ icon.active }}"
      mode="aspectFit"
      style="width: 30px; height: 18px;"
    />
    自定義
  </van-tabbar-item>
  <van-tabbar-item icon="search">標(biāo)簽</van-tabbar-item>
  <van-tabbar-item icon="setting-o">標(biāo)簽</van-tabbar-item>
</van-tabbar>

這時(shí)候就可以進(jìn)行加載

到此這篇關(guān)于微信小程序 TabBar 紅點(diǎn)提醒解決方案的文章就介紹到這了,更多相關(guān)微信小程序 TabBar 紅點(diǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • js中document.write和document.writeln的區(qū)別

    js中document.write和document.writeln的區(qū)別

    這篇文章主要介紹了js中document.write和document.writeln的區(qū)別,需要的朋友可以參考下
    2018-03-03
  • JS的函數(shù)調(diào)用棧stack size的計(jì)算方法

    JS的函數(shù)調(diào)用棧stack size的計(jì)算方法

    本篇文章給大家分享了關(guān)于JS的函數(shù)調(diào)用棧stack size的計(jì)算方法的相關(guān)知識(shí)點(diǎn),有興趣的朋友參考學(xué)習(xí)下。
    2018-06-06
  • JS模塊與命名空間的介紹

    JS模塊與命名空間的介紹

    JS模塊與命名空間的介紹,需要的朋友可以參考一下
    2013-03-03
  • JavaScript實(shí)現(xiàn)移動(dòng)端輪播效果

    JavaScript實(shí)現(xiàn)移動(dòng)端輪播效果

    這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)移動(dòng)端輪播效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • javascript實(shí)現(xiàn)繼承的簡(jiǎn)單實(shí)例

    javascript實(shí)現(xiàn)繼承的簡(jiǎn)單實(shí)例

    這篇文章主要介紹了javascript實(shí)現(xiàn)繼承的簡(jiǎn)單實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2015-07-07
  • 基于JavaScript實(shí)現(xiàn)貪吃蛇游戲

    基于JavaScript實(shí)現(xiàn)貪吃蛇游戲

    這篇文章主要為大家詳細(xì)介紹了基于JavaScript實(shí)現(xiàn)貪吃蛇游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • JavaScript實(shí)現(xiàn)相冊(cè)彈窗功能(zepto.js)

    JavaScript實(shí)現(xiàn)相冊(cè)彈窗功能(zepto.js)

    這篇文章主要介紹了JavaScript基于zepto.js實(shí)現(xiàn)相冊(cè)彈窗功能的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • 使用JavaScript實(shí)現(xiàn)一個(gè)簡(jiǎn)易的熱更新

    使用JavaScript實(shí)現(xiàn)一個(gè)簡(jiǎn)易的熱更新

    熱更新是指在應(yīng)用程序運(yùn)行時(shí),對(duì)程序的部分內(nèi)容進(jìn)行更新,而無(wú)需重啟整個(gè)應(yīng)用程序,熱更新是在不停止整個(gè)應(yīng)用程序的情況下,將新的代碼、資源或配置應(yīng)用于正在運(yùn)行的應(yīng)用程序,本文講給大家介紹一下使用JavaScript實(shí)現(xiàn)一個(gè)簡(jiǎn)易的熱更新,需要的朋友可以參考下
    2023-08-08
  • JS Generator函數(shù)yield表達(dá)式示例詳解

    JS Generator函數(shù)yield表達(dá)式示例詳解

    這篇文章主要為大家介紹了JS Generator函數(shù)yield表達(dá)式示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • JavaScript prototype 使用介紹

    JavaScript prototype 使用介紹

    用過(guò)JavaScript的同學(xué)們肯定都對(duì)prototype如雷貫耳,但是這究竟是個(gè)什么東西卻讓初學(xué)者莫衷一是,只知道函數(shù)都會(huì)有一個(gè)prototype屬性,可以為其添加函數(shù)供實(shí)例訪問(wèn),其它的就不清楚了,最近看了一些 JavaScript高級(jí)程序設(shè)計(jì),終于揭開了其神秘面紗
    2013-08-08

最新評(píng)論