WEB开发者之混合开发APP(十二), 页面间的参数传递方式

混合开发app中,页面之间的参数传递方式,主要使用以下两种。


1. 新建页面的参数传递

传递参数:

//获取商品分类id
var id = '121212';

//直接打开产品分类页面,传递参数pid
mui.openWindow({
   url:'products.html',
   id:'products.html',
   extras:{
       pid:id
   }
});

获取参数:
products.html页面获取参数需要写在mui.plusReady中,如下:

 mui.plusReady(function(){
    var self = plus.webview.currentWebview();     //获取当前页面webview
    var pid = self.pid == null ? "" : self.pid;   //获取传递给当前页面的参数pid
 });

2. 预加载页面参数传递

传递参数:

//预加载页面
var detailPage = mui.preload({
    url:'productdetail.html',
    id:'productdetail.html'
});

//获取商品id
var id ='12222';  

//触发详情页自定义事件,传递参数id
mui.fire(detailPage,'productInfo',{id:id});

//打开详情页面
mui.openWindow({
     id:"productdetail.html"
 });

获取参数:
productdetail.html中获取参数方式,在自定义事件productInfo中,

//自定义事件,获取参数id
window.addEventListener('productInfo',function(event){
        var id = event.detail.id;  //获取传递的id值,event.detail.xx获取xx的值
});

懂Html就能开发App,博文持续更新,博主QQ:260737830!

猜你喜欢

转载自blog.csdn.net/KnuthZ/article/details/80860919