uni-app 添加顶部导航栏并且更换图标;动态判断导航栏消息提醒的小红点是否显示

系统管理员 2022-12-08 15:53 526阅读 0赞

在这里插入图片描述
效果如上图所示,点击消息按钮跳转到新页面。

page.json中如下配置:

  1. {
  2. "path": "pages/index/index",
  3. // "style": {
  4. // "navigationStyle":"custom"
  5. // }
  6. "style" : {
  7. "navigationBarTitleText" : "北海救助局移动平台",
  8. "app-plus" : {
  9. "titleNView" : {
  10. "buttons" : [
  11. //显示小红点
  12. {
  13. "text": "\ue63e",
  14. "fontSrc": "/static/img/xiaoxi.ttf",
  15. "fontSize" : "24",
  16. "redDot" : true
  17. }
  18. //显示消息条数
  19. // {
  20. // "text": "\ue534",
  21. // "fontSrc": "/static/uni.ttf",
  22. // "fontSize": "22px",
  23. // "badgeText" : "12"
  24. // }
  25. ]
  26. }
  27. }
  28. }
  29. },

在项目中引入字体图标的方法如下:
1.在阿里图标库找到想要的图标,并加入购物车
在这里插入图片描述

2.在右上角购物车中找到下载代码按钮,并下载下来
在这里插入图片描述
3.解压缩下载完成的文件,如下,把文件里的iconfont.ttf放到static文件夹里,然后再打开iconfont.css里查看unicode编码
在这里插入图片描述
在这里插入图片描述
4.最后把对应图标的编码填写到page.json的配置项里text,需要写成一个”\u***“,然后重启

  1. 导航图标的点击事件如下:

    onNavigationBarButtonTap: function() {

    1. uni.navigateTo({
    2. url: '../remind/index',
    3. success: res => { },
    4. fail: (err) => { console.log(err)},
    5. complete: (data) => { }
    6. });

    },

6.动态判断是否显示消息提醒的小红点

  1. if(data.length==0) {
  2. // #ifdef APP-PLUS
  3. var webView = this.$mp.page.$getAppWebview();
  4. //隐藏角标
  5. webView.hideTitleNViewButtonRedDot({
  6. index:0,
  7. });
  8. // #endif
  9. } else {
  10. // #ifdef APP-PLUS
  11. var webView = this.$mp.page.$getAppWebview();
  12. //显示角标
  13. webView.showTitleNViewButtonRedDot({
  14. index:0,
  15. });
  16. // #endif
  17. }

发表评论

表情:
评论列表 (有 0 条评论,526人围观)

还没有评论,来说两句吧...

相关阅读