欢迎光临,了解微信小程序开发,就上易用通!

微信小程序页面跳转传递值

发布:2018-01-25 10:47浏览: 来源:网络 作者:tianshu

微信小程序导航有两种形式:一种是在写在js中进行跳转,另一种是写在wxml页面中进行跳转。

1、js导航

(1)、wx.navigateTo(OBJECT) :保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面。

微信小程序页面跳转传递值(图1)

  1. [javascript] view plain copy
  2. wx.navigateTo({  
  3.   url: 'test?id=1'  
  4. })  

获取传递的值:


  1. //test.js  
  2. Page({  
  3.   onLoad: function(option){  
  4.     console.log(option.id)  
  5.   }  
  6. })  


(2)、wx.redirectTo(OBJECT):关闭当前页面,跳转到应用内的某个页面。

微信小程序页面跳转传递值(图2)

  1. wx.redirectTo({  
  2.   url: 'test?id=1'  
  3. })  

(3)、wx.navigateBack(OBJECT):关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages()) 获取当前的页面栈,决定需要返回几层。

 

2、wxml导航

navigator:页面链接。

 

微信小程序页面跳转传递值(图3)

注:navigator-hover默认为{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;}, <navigator/>的子节点背景色应为透明色


示例代码:

  1. /** wxss **/  
  2. /** 修改默认的navigator点击态 **/  
  3. .navigator-hover {  
  4.     color:blue;  
  5. }  
  6. /** 自定义其他点击态样式类 **/  
  7. .other-navigator-hover {  
  8.     color:red;  
  9. }
  1. <view class="btn-area">  
  2.   <navigator url="navigate?title=navigate" hover-class="navigator-hover">跳转到新页面</navigator>  
  3.   <navigator url="redirect?title=redirect" redirect hover-class="other-navigator-hover">在当前页打开</navigator>  
  4. </view>


获取页面传递的值:


  1. // redirect.js navigator.js  
  2. Page({  
  3.   onLoad: function(options) {  
  4.     this.setData({  
  5.       title: options.title  
  6.     })  
  7.   }  
  8. })  





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。