使用HBuilder快速搭建App页面 2018-10-22

2018-10-22  本文已影响0人  Mr_Du_Biao

MUI:文档

动态操作
    document.getElementById("setting").addEventListener("tap",function(){
        mui.openWindow({
            url:"login.html",
            id:"login.html",
            styles:{
                top:"0px",
                bottom:"50px"
            }
        })
    })
 document.getElementById("setting").addEventListener("tap",function(){
        mui.openWindow({
            url:"login.html",
            id:"login.html",
            styles:{
                top:"0px",
                bottom:"50px"
            },
            extras:{
                user_id:"hahaha",
            }
        })
    })
    var Sdata =null;
        mui.plusReady(function(){
            Sdata= plus.webview.currentWebview();
            mui.toast(Sdata.user_id);
        })

如果想用plus就必须在plusReady下使用,否则报错

   mui.plusReady(function(){})
    document.getElementById("btn").addEventListener("tap",function(){
        var login_page = plus.webview.getWebviewById("login.html");
        mui.fire(login_page,"hello",{name:"jinwangba"});  # hello 是开火到另一个页面的事件,{name:"jinwangba"}是传过去的值
    })
document.addEventListener("hello",function(data){
            
            mui.toast(data.detail.name )
        })
开火方:
document.getElementById("clear_btn").addEventListener("tap",function(){
            var index = plus.webview.getWebviewById("HBuilder");
            mui.fire(index,"dianliangshouye");
        })
接受方
    document.addEventListener("dianliangshouye",function(){
        var index_btn = document.getElementById("index_page");
        var set_btn = document.getElementById("setting");
        index_btn.className = "mui-tab-item mui-active";
        set_btn.className ="mui-tab-item"  # 熄灭别的
    })

HBuilder 是首页的id

        document.getElementById("login_btn").addEventListener("tap",function(){
            
            var username = document.getElementById("username").value;
            var pwd = document.getElementById("pwd").value;
            mui.post(
                "http://192.168.12.11:9527/login",
                {"username":username,"password":pwd},
                function(data){
                    mui.toast(data.msg);
                    open_user_info(data.data);
                }
                
            )
        })

登录成功直接跳转

    document.getElementById("login_btn").addEventListener("tap",function(){
            
            var username = document.getElementById("username").value;
            var pwd = document.getElementById("pwd").value;
            mui.post(
                "http://192.168.12.11:9527/login",
                {"username":username,"password":pwd},
                function(data){
                    mui.toast(data.msg);
                    open_user_info(data.data);
                }
                
            )
        })
        
        function open_user_info(user_info){
            mui.openWindow({
                url:"user_info.html",
                id:"user_info.html",
                styles:{
                    top:"0px",
                    bottom:"50px"
                },
                extras:user_info
            })
        }

打开页面直接显示传过来的数据

  mui.plusReady(function(){
        var Sdata = plus.webview.currentWebview();
        document.getElementById("username").innerText = Sdata.username;
        document.getElementById("user_id").innerText = Sdata.user_id;
        document.getElementById("nickname").innerText = Sdata.nickname;
    })
上一篇 下一篇

猜你喜欢

热点阅读