uniapp学习系列二之登录验证

登录验证

简单验证

判空提示,密码圆点显示,固定账号密码

<template>
	<view class="login bg-gradual-green"><!-- 背景颜色bg-gradual-green渐变色 -->
		<view class="content bounceInDown">
			<!-- 头部logo -->
			<view class="header">
				<image src="../../common/logo.png"></image>
			</view>
			
			<view class="systemName">
				学习系统
			</view>
			
			<!-- 主体表单 -->
			<view class="main">
				<form>
					<view class="cu-form-group margin-top account">
						<view class="title"><text class="lg cuIcon-my"></text></view>
						<input class="inputText" placeholder="输入账户" name="codeNum" v-model="codeNum" ></input>
					</view>
					<!-- v-model是双向绑定值  密码输入框添加password后内容不可见-->
					<view class="cu-form-group margin-top account">
						<view class="title"><text class="lg cuIcon-lock"></text></view>
						<input class="inputText" placeholder="输入密码" password name="password" v-model="password" ></input>
					</view>
					<button class="cu-btn round lg btnlogin"  @click="Login()" >登 录</button>
				</form>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				codeNum:'',
				password:''
			}
		},
		methods: {
			Login: function(){
				let that=this;
				
				if(that.codeNum == ''){
					uni.showToast({
						title: '请输入账户',
						icon: 'none',
						duration:1000
					});
					return false;
				}
				
				if(that.password == ''){
					uni.showToast({
						title: '请输入密码',
						icon: 'none',
						duration:1000
					});
					return false;
				}
				
				if(that.codeNum == 'admin' && that.password == '123'){
					uni.navigateTo({
						url: '../index/index',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
			}
		}
	}
</script>
复杂验证

调用接口判断账户密码

<script>
	export default {
		data() {
			return {
				codeNum:'',
				password:''
			}
		},
		methods: {
			Login: function(){
				let that=this;
				
				if(that.codeNum == ''){
					uni.showToast({
						title: '请输入账户',
						icon: 'none',
						duration:1000
					});
					return false;
				}
				
				if(that.password == ''){
					uni.showToast({
						title: '请输入密码',
						icon: 'none',
						duration:1000
					});
					return false;
				}
				
				/* if(that.codeNum == 'admin' && that.password == '123'){
					uni.navigateTo({
						url: '../index/index',
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				} */
				uni.request({
					url: 'https://www.example.com/request', //仅为示例,并非真实接口地址。
					method:'POST',
					data: {
					    codeNum: that.codeNum,
						password: that.password
					},
					header: {
					    'content-type': 'application/json' //自定义请求头信息
					},
					success: (res) => {
					    // console.log(res.data);
					    uni.navigateTo({
					    	url: '../index/index',
					    	success: res => {},
					    	fail: () => {},
					    	complete: () => {}
					    });
					}
				});
			}
		}
	}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值