您的位置:首页 > 产品设计 > UI/UE

mui中页面之间传值

2017-07-30 08:42 253 查看
一种是在加载跳转页面时附加参数

mui('.mui-table-view').on('tap','.mui-table-view-cell',function(){
var cell_id = this.getAttribute('id');
mui.openWindow({
id:'dynamics_detail.html',
url:'dynamics_detail.html',
extras:{
the_id:cell_id
}
});
});


下面是在跳转后页面接收值

mui.plusReady(function() {
this_phoneNum = localStorage.getItem('phoneNum');
var self = plus.webview.currentWebview();
id = self.the_id;
sendRequest();
});


当然也有一种情况是你想返回一个值给前一个页面,可以通过触发事件来传值

例如:request_person.html要返回值给new_requesst.html

request_person.html:

mui('.mui-table-view').on('tap','.mui-table-view-cell',function(){
var id = this.getAttribute('id');
var new_request = plus.webview.getWebviewById('new_request.html');
mui.fire(new_request,'requestPerson',{id:id});
mui.openWindow({
id:'new_request.html',
})
})


new_request.html:

window.addEventListener('requestPerson',function(event){
//获得事件参数
var id = event.detail.id;
requestPerson = id;
document.getElementById('requestList').innerText = id;
})


当然在页面之间传值更为简单方式,就是使用web储存,将所用的值存在客户端

localStorage.setItem("name",acount);
localStorage.getItem("name");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息