提供一个vue前端页面示例,样式使用elementui美化,包括登录和注册的切换,注册信息保存到仓库,登录信息通过仓库数据验证,一个可以上传图片到仓库并且实时显示上传图片的轮播图
时间: 2023-10-16 15:09:01 浏览: 275
以下是一个简单的Vue前端页面示例,使用Element UI美化,包括登录和注册的切换,注册信息保存到仓库,登录信息通过仓库数据验证,一个可以上传图片到仓库并实时显示上传图片的轮播图。
```html
<template>
<div class="login-container">
<el-card class="login-card" v-show="loginVisible">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-width="80px">
<el-form-item label="账号" prop="username">
<el-input v-model="loginForm.username"></el-input>
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input type="password" v-model="loginForm.password"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="login">登录</el-button>
<el-button @click="showRegister">注册</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="register-card" v-show="registerVisible">
<el-form ref="registerForm" :model="registerForm" :rules="registerRules" label-width="80px">
<el-form-item label="账号" prop="username">
<el-input v-model="registerForm.username"></el-input>
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input type="password" v-model="registerForm.password"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="register">注册</el-button>
<el-button @click="showLogin">登录</el-button>
</el-form-item>
</el-form>
</el-card>
<el-carousel :interval="5000">
<el-carousel-item v-for="(item, index) in images" :key="index">
<img :src="item" class="carousel-image" />
</el-carousel-item>
</el-carousel>
<el-upload
class="upload-image"
action="/api/upload"
:on-success="handleSuccess"
:show-file-list="false"
>
<i class="el-icon-plus"></i>
</el-upload>
</div>
</template>
<script>
export default {
data() {
return {
loginVisible: true,
registerVisible: false,
loginForm: {
username: '',
password: ''
},
registerForm: {
username: '',
password: ''
},
images: []
}
},
computed: {
loginRules() {
return {
username: [{ required: true, message: '请输入账号', trigger: 'blur' }],
password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
}
},
registerRules() {
return {
username: [{ required: true, message: '请输入账号', trigger: 'blur' }],
password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
}
}
},
methods: {
showRegister() {
this.loginVisible = false
this.registerVisible = true
},
showLogin() {
this.loginVisible = true
this.registerVisible = false
},
login() {
this.$refs.loginForm.validate(valid => {
if (valid) {
// TODO: 登录验证逻辑
} else {
return false
}
})
},
register() {
this.$refs.registerForm.validate(valid => {
if (valid) {
// TODO: 注册验证逻辑
} else {
return false
}
})
},
handleSuccess(response) {
this.images.push(response.url)
}
}
}
</script>
<style scoped>
.login-container {
display: flex;
flex-direction: column;
align-items: center;
}
.login-card,
.register-card {
width: 400px;
margin-top: 50px;
}
.carousel-image {
width: 100%;
height: 300px;
object-fit: cover;
}
.upload-image {
width: 200px;
height: 200px;
margin-top: 50px;
display: flex;
justify-content: center;
align-items: center;
border: 1px solid #ebeef5;
border-radius: 4px;
font-size: 28px;
color: #8c939d;
background-color: #f5f7fa;
cursor: pointer;
}
</style>
```
在此示例中,我们使用了Element UI来美化登录和注册表单,并使用计算属性来定义表单验证规则。登录和注册表单都有一个按钮,用于提交表单数据并进行验证。
我们还使用了Element UI的轮播组件和上传组件来实现图片上传和展示功能。当用户上传图片时,我们将其添加到一个数组中,并使用`v-for`指令来将其渲染为一系列轮播项。
请注意,该示例中的上传和保存图片到仓库的逻辑需要根据具体的业务需求进行实现。
阅读全文