微信小程序---tabBar&页面跳转

微信小程序---tabBar&页面跳转,第1张

1、tabBar

在appjson文件中添加tabBar节点。tabBar是小程序客户端底部或顶部tab栏的实现。

(1)tabBar相关属性

color:tab上的文字默认颜色,仅支持十六进制颜色。

selectedColor:tab上的文字选中时的颜色,仅支持十六进制颜色。

backgroundColor:tab的背景色,仅支持十六进制颜色。

borderStyle:tabbar上边框的颜色, 仅支持 black / white。

position:tabBar的位置,默认值是: bottom,仅支持 bottom / top。当 position 为 top 时,不显示 icon。

custom:自定义tabBar。

"tabBar": {

    "color": "#000000",

    "selectedColor": "#336699",

    "backgroundColor": "#ffffff",

    "borderStyle": "black",

    "position": "bottom"

  }

(2)list

list:tab的列表。

list 接受一个数组,只能配置最少 2 个、最多 5 个 tab。

pagePath:页面路径,必须在pages 中先定义。

text:tab 上按钮文字。

iconPath:路径,icon 大小限制为 40kb,建议尺寸为 81px 81px,不支持网络。selectedIconPath:选中时的路径,icon 大小限制为 40kb,建议尺寸为 81px 81px,不支持网络。

    "list": [

      {

        "text": "首页",

        "pagePath": "pages/index/index",

        "iconPath": "assets/icon/homepng",

        "selectedIconPath": "assets/icon/home2png"

      },

      {

        "text": "列表",

        "pagePath": "pages/list/list",

        "iconPath": "assets/icon/listpng",

        "selectedIconPath": "assets/icon/list2png"

      }

]

2、页面跳转

(1)跳转普通页面

方法① navigator组件

 <!-- 跳转到普通页,可以通过返回按钮返回 -->

 <navigator url="/detail/detail">到详情页</navigator>

方法② navigateTo()方法

navigateTo()方法,用于跳转普通页面。

<view bindtap="gotoDetail">到详情页</view>

gotoDetail(){

    //使用全局api跳转,navigateTo()方法,用于跳转普通页面

    wxnavigateTo({

      url: '/detail/detail',

    })

   }

(2)跳转tabBar页面

方法① navigator组件

如果要使用navigator组件跳转tabBar页面,需要设置open-type="switchTab"。

 <!-- 跳转到tabBar页面,不可以通过返回按钮返回。因为跳转到指定的tabBar页面后,会关闭其他所有页面 -->

<navigator url="/list/list" open-type="switchTab">到列表页</navigator>                                                                                      

方法② switchTab()方法

switchTab()方法,用于跳转tabBar页面。

  <view bindtap="gotoList">到列表页</view>

gotoList(){

    wxswitchTab({

      url: '/list/list',

    })

  }

检查跳转的地址、检查跳转的地址是否注册、使用wxswitchTab。

1、检查你跳转的地址是否有误。

2、检查你要跳转的地址是否在appjs中注册过。

3、当你跳转的地址位于TabBar中时,要使用wxswitchTab来跳转页。

以上就是关于微信小程序---tabBar&页面跳转全部的内容,包括:微信小程序---tabBar&页面跳转、小程序无法跳转到php页面、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9292852.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-26
下一篇2023-04-26

发表评论

登录后才能评论

评论列表(0条)

    保存