微信小程序

1,内置api

显示提示

  • showToast

本地存储

  • wx.setStorageSync(key,value)

本地取

  • wx.getStorageSync(key)
  • wx.request 网络请求

2,生命周期

onLoad 页面加载完毕

onPullDownRefresh 下拉刷新

onReachBottom 触底更新

3,页面切换

这是最常见的一种跳转方式,相当于html里的a标签.但需要注意的是 该方法不能跳转tabbar页面.

2,wx.navigateTo.

通过构造js函数,在函数中调用该接口可实现页面跳转的效果.但该接口同样不能跳转tabbar页面.跳转后左上角有返回小箭头,点击可返回原本页面.

格式为:

复制代码
//<!**wxml文件**>
<view class="select_calculator" bindtap="next_calculator">
//js文件
next_calculator:function () {
    wx.navigateTo({
      url: '/pages/calculator/calculator',
    })

3,wx.redirectTo.

关闭当前页面,跳转到应用内的某个页面(不能跳转tabbar页面)。类似于html中的 window.open('...');

跳转后左上角出现返回小箭头,点击后可返回原本页面.

格式为:

复制代码
<view>
  <navigator open-type="redirect" url="/pages/event/event">跳转并替换</navigator>
</view>

4,wx.switchTab.

跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面;该方法只能跳转tabbar页面.

5,wx.reLaunch.

关闭所有页面,打开到应用内的某个页面。 跟 wx.redirectTo 一样左上角不会出现返回箭头,但两者却不完全相同;

格式为:

复制代码
<view>
  <navigator open-type="reLaunch">重启</navigator>
</view>

4 ,tabBar 全局配置

tabBar 是移动端应用常见的页面效果, 用于实现多页面 的快速切换 。

小程序中通常将其分为:

1,底部 tabBar

2,顶部 tabBar

1, 注意:

  1. tabBar中只能配置最少 2 个、最多 5 个 tab 页签
  2. 当渲染顶部 tabBar 时,不显示 icon,只显示文本

2,tabBar 的 6 个组成部分

复制代码
① backgroundColor:				tabBar 的背景色

② selectedIconPath:			选中时的图片路径

③ borderStyle:					tabBar 上边框的颜色

④ iconPath:					未选中时的图片路径

⑤ selectedColor:				tab 上的文字选中时的颜色

⑥ color:						tab 上文字的默认(未选中)颜色

3. tabBar 节点的配置项

4. 每个 tab 项的配置选项

5,全局配置 - 案例:配置 tabBar

配置 tabBar 选项

① 打开 app.json 配置文件,和 pages、window 平级,新增 tabBar 节点

② tabBar 节点中,新增 list 数组 ,这个数组中存放的,是每个 tab 项的配置对象

③ 在 list 数组中, 新增每一个 tab 项的配置对象 。对象中包含的属性如下: pagePath 指定当前 tab 对应的页面路径 【 必填 】

text 指定当前 tab 上按钮的文字【 必填】

iconPath 指定当前 tab 未选中时候的图片路径【可选】

selectedIconPath 指定当前 tab 被选中后高亮的图片路径【可选】

代码如下:
复制代码
{
    "pages": [
        "pages/hone/hone",
        "pages/Profile/Profile",
        "pages/experience/experience",
        "pages/skill/skill",
        "pages/index/index",
        "pages/logs/logs"
    ],
    "tabBar":{
        "color": "#777",
        "selectedColor": "#1cb9ce",
        "list":[
            {"pagePath": "pages/hone/hone","text":"简历信息","iconPath": "/pages/img/icon08.png","selectedIconPath": "/pages/img/icon08.png"},
            {"pagePath": "pages/skill/skill","text":"个人技能","iconPath": "/pages/img/icon04.png","selectedIconPath": "/pages/img/icon04.png"},
            {"pagePath": "pages/experience/experience","text":"项目经历","iconPath": "/pages/img/icon02.png","selectedIconPath": "/pages/img/icon02.png"},
            {"pagePath": "pages/Profile/Profile","text":"自我评价","iconPath": "/pages/img/icon06.png","selectedIconPath": "/pages/img/icon06.png"}
        ]
    },
    "window": {
        "backgroundTextStyle": "light",
        "navigationBarBackgroundColor": "#fff",
        "navigationBarTitleText": "Weixin",
        "navigationBarTextStyle": "black"
    },
    "style": "v2",
    "sitemapLocation": "sitemap.json"
}

6,页面传参

wxml 代码如下:
复制代码
<view>
  <navigator open-type="navigate" url="/pages/event/event?name=mumu&age=18">事件event</navigator>
</view>
<view>
  <navigator open-type="redirect" url="/pages/event/event?name=曾庆林&age=33">跳转并替换</navigator>
</view>
js 代码如下:
复制代码
/**
   * 页面的初始数据
   */
  data: {
    num:null,
  },
  goEvent(e){
    // 获取到传递的参数type
    var type = e.target.dataset.type;
    // 如果type值是redirect 替换跳转
    if(type=="redirect"){
      wx.redirectTo({
        url: "/pages/event/event",
      })
    }else{
      // 否则就普通跳转
      wx.navigateTo({
        url: '/pages/event/event',
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 更新导航栏的标题
    wx.setNavigationBarTitle({
      title: '导航与跳转',
    })
   
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({num:app.globalData.num})
  },
页面传递的参数
复制代码
<view>页面传递的参数</view>
<view>
姓名:{{name}},年龄{{age}}
</view>
相关推荐
程序鉴定师14 小时前
西安App开发推荐与业界认可的优秀实践
大数据·小程序
纤纡.20 小时前
HarmonyOS 鸿蒙 ArkTS 实战:从零开发生肖集卡抽奖小程序
华为·小程序·harmonyos·deveco studio
Lsx_20 小时前
H5 嵌入微信 / 支付宝 / 抖音小程序 WebView:调用原生能力完整方案
前端·微信小程序·webview
我是伪码农1 天前
小程序26-50
小程序
计算机学姐1 天前
基于微信小程序的图书馆座位预约系统【uniapp+springboot+vue】
vue.js·spring boot·微信小程序·小程序·java-ee·uni-app·intellij-idea
焦糖玛奇朵婷2 天前
健身房预约小程序开发、设计
java·大数据·服务器·前端·小程序
Dragon Wu2 天前
Taro v4.2.0 scss使用“@/xxx“的配置方法
前端·小程序·taro·scss
WKK_2 天前
uniapp 微信小程序使用TextEncoder,arrayBufferToBase64
微信小程序·小程序·uni-app
舟遥遥娓飘飘2 天前
面向零基础初学者,从环境搭建到发布上线,手把手教你开发第一个微信小程序(第3章-认识项目结构)
微信小程序·小程序·notepad++
优睿远行2 天前
微信小程序自定义组件开发实战:从封装到发布的全流程指南
微信小程序·小程序·notepad++