亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序 TabBar 紅點提醒完美解決方案

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

TabBar 紅點提醒,很多小程序都需要這個功能比如聊天小程序,電商小程序等
這時候我們需要進行自定義 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": "接口"
    }]
  }
}

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

添加代碼文件

在跟目錄中創(chuàng)建文件夾和組件結構

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

可以看到這塊是一個自定義組建,如果不能出現(xiàn)該效果,可能是因為代碼基礎調試庫的問題,通常在設置自定義 TabBar 提示 TypeError,這時候需要在 詳情-》本地設置-》修改基礎調試庫,不要使用灰度測試版本,我這里實用的是 3.4.2 版本沒有問題

實用 Vant 組建 TabBar

引用

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

設置 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">標簽</van-tabbar-item>
        <van-tabbar-item icon="setting-o">標簽</van-tabbar-item>
      </van-tabbar>

設置 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 文件

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

設置 customjs 結構

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
      });
    }
  }
});

設置 wxml 結構

<!--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">標簽</van-tabbar-item>
  <van-tabbar-item icon="setting-o">標簽</van-tabbar-item>
</van-tabbar>

這時候就可以進行加載

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

相關文章

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

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

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

    JS的函數(shù)調用棧stack size的計算方法

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

    JS模塊與命名空間的介紹

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

    JavaScript實現(xiàn)移動端輪播效果

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

    javascript實現(xiàn)繼承的簡單實例

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

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

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

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

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

    使用JavaScript實現(xiàn)一個簡易的熱更新

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

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

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

    JavaScript prototype 使用介紹

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

最新評論