美文网首页
小程序之页面跳转和参数传递

小程序之页面跳转和参数传递

作者: LuckTime | 来源:发表于2017-07-27 14:01 被阅读179次

小程序官网关于Navigator介绍:

image.png
open-type = navigate
对应 wx.navigateTo的功能

open-type = redirect
对应 wx.redirectTo的功能

open-type = switchTab
对应 wx.switchTab的功能

open-type = reLaunch
对应 wx.reLaunch的功能
[1.1.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html)

navigateBack
对应 wx.navigateBack的功能


页面跳转时传递

主页面:

<!-- sample.wxml -->
<view class="btn-area">
  <navigator url="/page/navigate/navigate?title=newPagePath" hover-class="navigator-hover">跳转到新页面</navigator>
  <navigator url="../../redirect/redirect/redirect?title=重定向页面&ohterParmas=123" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator>
  <navigator url="/page/index/index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator>
</view>
这里是带参跳转的,一个参数就用?=title,如果多个参数就是用?=title=”“&ohterParmas=”“。

页面跳转后,onload接受参数

Page({
  data:{
//不需要再写user_id。
  },

    onLoad(options) {
      console.log('onLoad')
      console.log(options.user_id)
      if (options.user_id) {
        this.setData({
          user_id: options.user_id
        })
      } else {
        this.setData({
          user_id: '暂无'
        })
      }
    }

相关文章

网友评论

      本文标题:小程序之页面跳转和参数传递

      本文链接:https://www.haomeiwen.com/subject/gpfzkxtx.html