uniapp写一个登录页面
时间: 2023-06-18 19:05:41 浏览: 48
很高兴为您解答,可以参考以下步骤来写一个登录页面:
1. 创建一个uniapp项目,并在项目中创建一个登录页面;
2. 在登录页面中添加用户名和密码输入框,以及一个登录按钮;
3. 在登录按钮的点击事件中,添加验证用户名和密码的逻辑;
4. 如果验证通过,跳转到相应的页面;
5. 如果验证不通过,弹出提示框,提示用户名或密码错误。
相关问题
用uniapp写一个登录页面
好的,以下是用uniapp写一个登录页面的示例代码:
<template>
<view class="container">
<view class="header">欢迎登录</view>
<form class="form" @submit="submitForm">
<label class="label">
<text class="text">用户名:</text>
<input class="input" v-model="username" type="text" name="username" />
</label>
<label class="label">
<text class="text">密码:</text>
<input class="input" v-model="password" type="password" name="password" />
</label>
<button class="button" type="submit">登录</button>
</form>
</view>
</template>
<script>
export default {
data() {
return {
username: '',
password: '',
};
},
methods: {
submitForm(event) {
event.preventDefault();
// 处理登录逻辑
},
},
};
</script>
<style>
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f5f5f5;
}
.header {
font-size: 24px;
font-weight: bold;
margin: 16px;
}
.form {
display: flex;
flex-direction: column;
gap: 16px;
padding: 16px;
border-radius: 8px;
background-color: #fff;
}
.label {
display: flex;
flex-direction: column;
gap: 8px;
}
.text {
font-size: 18px;
font-weight: bold;
}
.input {
padding: 8px;
border-radius: 4px;
border: 1px solid #ccc;
}
.button {
padding: 8px 16px;
border-radius: 4px;
background-color: #007aff;
color: #fff;
font-size: 18px;
font-weight: bold;
cursor: pointer;
}
</style>
用uniapp写一个登录界面
A:
1. 在uniapp中创建一个页面,命名为“login”
2. 在“login”页面中,编写一个登录表单,包含两个输入框:一个输入框用于输入账号,另一个输入框用于输入密码。同时,在表单中添加一个登录按钮,用于提交表单。
3. 在“login”页面中,添加一段脚本代码,用于获取账号和密码的输入值,验证用户输入是否正确,如果正确,则跳转到主页(或指定页面),否则则弹出错误提示。
示例代码:
```
<template>
<view>
<form>
<input type="text" name="account" placeholder="请输入账号" v-model="account" />
<input type="password" name="password" placeholder="请输入密码" v-model="password" />
<button type="submit" @click="login">登录</button>
</form>
</view>
</template>
<script>
export default {
data() {
return {
account: '',
password: '',
};
},
methods: {
login() {
// 验证输入
if (this.account && this.password) {
// 跳转到主页
uni.switchTab({
url: '/pages/home/home',
});
} else {
// 显示错误提示
uni.showToast({
title: '账号或密码不能为空!',
icon: 'none',
});
}
},
},
};
</script>
```
4. 在“login”页面中,添加样式代码,美化登陆界面。
示例代码:
```
<style>
form {
margin-top: 100px;
display: flex;
flex-direction: column;
align-items: center;
}
input {
width: 80%;
margin-bottom: 30px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
width: 80%;
padding: 10px;
color: #fff;
background-color: #007aff;
border-radius: 5px;
border: none;
cursor: pointer;
}
button:active {
background-color: #0057b8;
}
</style>
```
以上就是使用uniapp编写登录界面的步骤和示例代码。