二、uni-app登录功能页面跳转

<template>
	<view class="content" style="width: 100%; height: 100%;">
		<view style="text-align: center;">
		</view>
			<text class="title" style="text-align: center; font-size: 40rpx; font-family: PingFangSC-Medium, PingFang SC; font-weight: bolder;">Ming-Afresh</text>
			<text class="title" style="text-align: center; font-size: 30rpx; font-family: PingFangSC-Medium, PingFang SC; margin-top: 100rpx;">账号密码登录</text>
		<view style="padding: 60rpx; position: absolute; top: 350rpx;">
			<view>
				<input class="input1" placeholder-style='color:#AAAAAA;' v-model='username' placeholder="请输入账户名" />
			</view>
			<view>
				<input class="input1" type='password' placeholder-style='color:#AAAAAA'  v-model='password' placeholder="请输入密码" />
			</view>
			<view style="height: 25rpx; color: #FF5C50; font-size: 26rpx; margin-top: 20rpx;">
				<span v-show='error'>用户不存在/密码错误</span>
				// v-show判断隐藏条件
			</view>
			<button style="margin-top: 60rpx; background-color: #6CCACF; border-radius: 45rpx; color: #FFFFFF; width: 200rpx;" @click="userLogin">登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				error: false,
				username: '',
				password: '',
			}
		},
		onLoad() {
			let isLogin = uni.getStorageSync('isLogin')
			if (isLogin) {
				uni.redirectTo({
					url: '../home/home'
					// 从本地缓存中同步获取指定 key:('isLogin') 对应的内容
					// 并进行页面之间传参
				})
			}
		},
		methods: {
			userLogin(e) {
				var that = this;
				uni.request({
					url: 'https://kz.ababjs.com/epkg/testhistorytest/login',
					// 后端接口地址 post方法
					method: 'POST',
					data: {
						username: that.username,
						password: that.password,
						rememberMe: false
					// 拿值
					},
					header: {
						'content-type': 'application/json'
					},
					success(res) {
						if (res.data.code == 0) {
							that.error = false
							uni.setStorageSync('isLogin', true)
							uni.setStorageSync('username', that.username)
							uni.redirectTo({
								url: '../home/home'
								// 触发点击事件成功后页面路由跳转
							})
						} else {
							that.error = true
							that.password = ''
						}
					},
					fail(err) {
					}
				});
			},
			
		}
	}
</script>

<style>
	page {
		background-image:linear-gradient(to bottom right,#6CCACF,#FBFCFB);
	}
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.text-login {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		border-radius: 20rpx;
		background: #ffffff;
		margin-top: 80rpx;
		width: 660rpx;
		height: 1050rpx;
	}
	.title {
		color: black;
		position: absolute;
		top: 200rpx;
	}
	.input1 {		
		height: 80rpx;
		width: 500rpx;
		padding: 10rpx;
		margin: 30rpx;
		background-color: #FBFBFB;
		border-radius: 45rpx;
	}
</style>

在这里插入图片描述

  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值