Hbuilder+MUI开发5+appHbuilder开发HBuilder开发

mui页面间传值

2017-09-24  本文已影响136人  REIGE

通过extras传值

mui.openWindow({
    url: url,
    id: "mid",
    extras: {
        msg: "传值"
    }
})
```javascript
可以通过`webview`对象获取参数。
```javascript
mui.plusReady(function () {
   var self = plus.webview.currentWebview();
   // 或 var self = plus.webview.getWebviewById('mid');
   console.log("extras:" + self.msg);
})

页面已创建,通过自定义事件传值

var wv= plus.webview.getWebviewById('mid');
mui.fire(wv,'send',{
    msg: 'aaaaa'
})

接收参数的页面

// 添加自定义事件监听
window.addEventListener('send',function(event){
  //获得事件参数
  var msg= event.detail.msg;
  console.log(msg);
});

evalJS

var wv= plus.webview.getWebviewById('mid');
var msg = "aaa";
wv.evalJS('send('+msg+')');

接收参数的页面

 // 接收参数的函数
function send(msg){
    console.log(msg);
} 

页面关闭后 回调上个页面的方法

mui.init({
    beforeback: function(){
        console.log("beforeback");
        var wvs=plus.webview.all();
        var index = plus.webview.getWebviewById(wvs[wvs.length-2].id);//获取下一个栈顶         
        //触发详情页面的newsId事件
        mui.fire(index,'reLoad',{});
        //返回true,继续页面关闭逻辑
        return true;
    }
});
上一篇 下一篇

猜你喜欢

热点阅读