uniapp+vue+uview适配安卓4.4项目实现简单登录和操作页面

简介: uniapp+vue+uview适配安卓4.4项目实现简单登录和操作页面

前言

大家好 我是歌谣 最近遇到了一个新的问题 就是兼容一个安卓4.4的平板仪器 利用react打包之后再用Hbulderx打包成apk之后白屏 于是就开始漫长的尝试过程


转折

多方测试发现 原生js可以识别 于是乎开始了原生js的开发

<!DOCTYPE html>
<html class="ui-page-login">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title></title>
        <link href="css/mui.min.css" rel="stylesheet" />
        <link href="css/style.css" rel="stylesheet" />
        <style>
            .area {
                margin: 20px auto 0px auto;
            }
            .mui-input-group {
                margin-top: 10px;
            }
            .mui-input-group:first-child {
                margin-top: 20px;
            }
            .mui-input-group label {
                width: 22%;
            }
            .mui-input-row label~input,
            .mui-input-row label~select,
            .mui-input-row label~textarea {
                width: 78%;
            }
            .mui-checkbox input[type=checkbox],
            .mui-radio input[type=radio] {
                top: 6px;
            }
            .mui-content-padded {
                margin-top: 25px;
            }
            .mui-btn {
                padding: 10px;
            }
            .link-area {
                display: block;
                margin-top: 25px;
                text-align: center;
            }
            .spliter {
                color: #bbb;
                padding: 0px 8px;
            }
            .oauth-area {
                position: absolute;
                bottom: 20px;
                left: 0px;
                text-align: center;
                width: 100%;
                padding: 0px;
                margin: 0px;
            }
            .oauth-area .oauth-btn {
                display: inline-block;
                width: 50px;
                height: 50px;
                background-size: 30px 30px;
                background-position: center center;
                background-repeat: no-repeat;
                margin: 0px 20px;
                /*-webkit-filter: grayscale(100%); */
                border: solid 1px #ddd;
                border-radius: 25px;
            }
            .oauth-area .oauth-btn:active {
                border: solid 1px #aaa;
            }
            .oauth-area .oauth-btn.disabled {
                background-color: #ddd;
            }
        </style>
    </head>
    <body>
        <header class="mui-bar mui-bar-nav">
            <h1 class="mui-title">登录</h1>
        </header>
        <div class="mui-content">
            <form id='login-form' class="mui-input-group">
                <div class="mui-input-row">
                    <label>账号</label>
                    <input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入账号">
                </div>
                <div class="mui-input-row">
                    <label>密码</label>
                    <input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
                </div>
            </form>
            <div class="mui-content-padded">
                <button  id='login' class="mui-btn mui-btn-block mui-btn-primary">登录</button>
            <!--    <div class="link-area"><a id='reg'>注册账号</a> <span class="spliter">|</span> <a id='forgetPassword'>忘记密码</a>
                </div> -->
            </div>
        </div>
        <script src="js/mui.min.js"></script>
        <script src="js/mui.enterfocus.js"></script>
        <script src="js/app.js"></script>
        <script>
            var login=document.getElementById("login");
            var account=document.getElementById("account")
            var password=document.getElementById("password")
            var test=document.getElementById("test")
            //监听点击事件
            login.addEventListener("tap",function () {
                mui.ajax('http://xxxxxx/pda/login',{
                    data:{
                        account:document.getElementById("account").value,
                        password:document.getElementById("password").value
                    },
                    dataType:'json',//服务器返回json格式数据
                    type:'post',//HTTP请求类型
                    timeout:10000,//超时时间设置为10秒;
                    headers:{'Content-Type':'application/json'},                  
                    success:function(response){
                        // test.innerHTML=JSON.stringify(response)
                        if(response.code==200){
                            window.location.href="./home.html"
                            mui.toast('登陆成功',{ duration:'long', type:'div' })
                        }else{
                            mui.toast('登陆失败',{ duration:'long', type:'div' })
                        }
                        //服务器返回响应,根据响应结果,分析是否登录成功;
                    },
                    error:function(xhr,type,errorThrown){
                        // test.innerHTML=JSON.stringify(xhr)
                        //异常处理;
                        console.log(type);
                    }
                });
            });
            //触发submit按钮的点击事件
            mui.trigger(login,'tap')
        </script>
    </body>
</html>

结果

结果遇到了一些问题 无法进行数据的双向绑定


实现结果

image.png


接着就开始换一种思路

利用uniapp+uview1.8+vue开发 login.vue

<template>
    <view class="content">
        <!--    <image class="logo" src="/static/logo.png"></image>
        <view class="text-area">
            <text class="title">
                uView - 多平台快速开发的UI框架
            </text>
        </view>
        <view class="button-demo">
            <u-button type="primary" plain @click="$u.route('/pages/login/login')">通用登录页展示</u-button>
        </view> -->
        <u-form :model="form" ref="uForm">
            <u-form-item label="姓名">
                <u-input v-model="form.account" placeholder="请输入账号"></u-input>
            </u-form-item>
            <u-form-item label="密码">
                <u-input v-model="form.password"  placeholder="请输入密码"></u-input>
            </u-form-item>
        </u-form>
        <view style="padding: 20px;">
        <u-button v-on:click="handleClick" type="primary" text="登录">登录</u-button>
        </view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                title: 'Hello',
                form: {
                    account: "",
                    password:""
                },
                status:"1"
            }
        },
        onLoad() {
        },
        methods: {
             handleClick(){
                // this.status="-1"
                // var that=this
                 uni.$u.http.post('http://xxxxxx',{account: this.form.account, password: this.form.password}).then(res => {
                      console.log(this,"22222")
                // that.status="-1"
                uni.navigateTo({
                    url: '/pages/index/index',
                });
                }).catch(err => {
                    console.log("-----------”")
                console.log(err,"11111")
                console.log("-----------”")
                })
            }
        }
    }
</script>
<style lang="scss" scoped>
    .content {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 40rpx;
    }
    .logo {
        height: 200rpx;
        width: 200rpx;
        margin-top: 100rpx;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 50rpx;
    }
    .text-area {
        display: flex;
        justify-content: center;
    }
    .title {
        font-size: 28rpx;
        color: $u-content-color;
    }
    .button-demo {
        margin-top: 80rpx;
    }
</style>
相关文章
|
存储 JavaScript
vue页面跳转取消上一个页面请求
本文介绍了在Vue中如何取消上一个页面的请求,以避免页面跳转时请求未完成导致的数据错误。核心方法是使用axios的请求拦截器设置请求的取消令牌(cancelToken),并在vuex中存储这些取消令牌的引用。当进行路由跳转时,通过路由守卫清除这些请求,达到取消上一个页面请求的目的。
510 2
|
10月前
|
人工智能 移动开发 JavaScript
如何用uniapp打包桌面客户端exe包,vue或者uni项目如何打包桌面客户端之electron开发-优雅草央千澈以开源蜻蜓AI工具为例子演示完整教程-开源代码附上
如何用uniapp打包桌面客户端exe包,vue或者uni项目如何打包桌面客户端之electron开发-优雅草央千澈以开源蜻蜓AI工具为例子演示完整教程-开源代码附上
1056 18
|
8月前
|
JSON 自然语言处理 前端开发
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
411 72
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
|
8月前
|
JavaScript 前端开发 算法
vue渲染页面的原理
vue渲染页面的原理
262 56
|
10月前
|
JavaScript 安全 API
iframe嵌入页面实现免登录思路(以vue为例)
通过上述步骤,可以在Vue.js项目中通过 `iframe`实现不同应用间的免登录功能。利用Token传递和消息传递机制,可以确保安全、高效地在主应用和子应用间共享登录状态。这种方法在实际项目中具有广泛的应用前景,能够显著提升用户体验。
1325 9
|
11月前
|
存储 监控 API
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
app开发之安卓Android+苹果ios打包所有权限对应解释列表【长期更新】-以及默认打包自动添加权限列表和简化后的基本打包权限列表以uniapp为例-优雅草央千澈
1044 11
|
JSON JavaScript 小程序
使用VSCode搭建UniApp + TS + Vue3 + Vite项目
`uniapp` 是一个基于 Vue.js 的框架,支持一次开发多端部署,深受前端开发者喜爱。本文详细介绍如何使用 `VSCode` 搭建 `uniapp` 项目,包括安装 `node` 和 `pnpm`、创建项目、安装扩展组件、配置 `Json` 文件注释及安装相关插件。通过这些步骤,你可以高效地使用 `VSCode` 开发 `uniapp` 项目,并享受代码提示和自动补全功能,提高开发效率。
916 24
使用VSCode搭建UniApp + TS + Vue3 + Vite项目
|
JavaScript API
vue尚品汇商城项目-day04【24.点击搜索按钮跳转后的页面商品列表、平台售卖属性动态展示(开发Search组件)】
vue尚品汇商城项目-day04【24.点击搜索按钮跳转后的页面商品列表、平台售卖属性动态展示(开发Search组件)】
201 1
vue尚品汇商城项目-day04【24.点击搜索按钮跳转后的页面商品列表、平台售卖属性动态展示(开发Search组件)】
|
移动开发 小程序 数据可视化
基于npm CLI脚手架的uniapp项目创建、运行与打包全攻略(微信小程序、H5、APP全覆盖)
基于npm CLI脚手架的uniapp项目创建、运行与打包全攻略(微信小程序、H5、APP全覆盖)
2245 3
|
小程序 前端开发 Java
SpringBoot+uniapp+uview打造H5+小程序+APP入门学习的聊天小项目
JavaDog Chat v1.0.0 是一款基于 SpringBoot、MybatisPlus 和 uniapp 的简易聊天软件,兼容 H5、小程序和 APP,提供丰富的注释和简洁代码,适合初学者。主要功能包括登录注册、消息发送、好友管理及群组交流。
334 0
SpringBoot+uniapp+uview打造H5+小程序+APP入门学习的聊天小项目

热门文章

最新文章