vue3的elementplus登录界面
时间: 2023-11-12 15:03:24 浏览: 85
VUE3+element plus实现的酷炫登录页面
4星 · 用户满意度95%
可以使用Element Plus的Form和Input组件来实现登录界面。具体步骤如下:
1. 在Vue组件中引入Form和Input组件:
```
<template>
<el-form>
<el-form-item label="用户名">
<el-input v-model="username"></el-input>
</el-form-item>
<el-form-item label="密码">
<el-input type="password" v-model="password"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="login">登录</el-button>
</el-form-item>
</el-form>
</template>
<script>
import { ElForm, ElFormItem, ElInput, ElButton } from 'element-plus';
export default {
components: {
ElForm,
ElFormItem,
ElInput,
ElButton,
},
data() {
return {
username: '',
password: '',
};
},
methods: {
login() {
// 处理登录逻辑
},
},
};
</script>
```
2. 在Vue组件中处理登录逻辑,可以使用axios发送POST请求到后端接口:
```
<script>
import axios from 'axios';
import { ElForm, ElFormItem, ElInput, ElButton } from 'element-plus';
export default {
components: {
ElForm,
ElFormItem,
ElInput,
ElButton,
},
data() {
return {
username: '',
password: '',
};
},
methods: {
async login() {
try {
const response = await axios.post('/api/login', {
username: this.username,
password: this.password,
});
// 处理登录成功逻辑
} catch (error) {
// 处理登录失败逻辑
}
},
},
};
</script>
```
阅读全文