用Spring Boot+Vue做微人事项目第一天

用Spring Boot+Vue做微人事项目系列目录

一、首先配置一个项目如何更便捷的启动,详细步骤如下图

前端框架用的是Element UI,后台用的是spring boot,写把前端写完,再写后台接口

使用npm i element-ui -S命令行在vue的生产配置里面下载Element UI

下载好了之后不能直接使用,还需要引用一下两行代码

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

在加上Vue.use(ElementUI);就可以在vue中使用element ui了

首先定义登录页Login.vue

<template>
    <div>
        <!--element ui的表单验证规则配置 用 :rules="rules"这是简写的,本来是v-model:rules="rules"-->
        <!--:model 表单里面的数据对象-->
        <el-form :rules="rules" :model="loginForm" class="loginContainer" ref="loginForm">
            <h3 class="loginTitle">系统登录</h3>
            <!--表单里面的每一项叫做<el-form-item></el-form-item,要加个prop属性,本来是不用加的,但是我们这个使用了字段校验,这种情况家就一定要加prop属性-->
            <el-form-item prop="username">
                <!--auto-complete:是否自动补全-->
                <el-input type="text" v-model="loginForm.username" auto-complete="off" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input type="password" v-model="loginForm.password" auto-complete="off" placeholder="请输入密码"></el-input>
            </el-form-item>
            <el-checkbox class="loginRember" v-model="checked"></el-checkbox>
            <el-button type="primary" style="width: 100%" @click="submitLogin">登录</el-button>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
            return{
                loginForm:{
                  username:"admin",
                  password:"123"
                },
                checked:true,
                rules:{
                    //required:true:用户名必填  如果没填就弹出““””“"请输入用户名",trigger:blur 触发的方式是blur
                    username:[{required:true,messsage:"请输入用户名",trigger:"blur"}],
                    password:[{required:true,message:"请输入密码",trigger:"blur"}]
                }
            }
        },
        methods:{
            submitLogin(){
                this.$refs.loginForm.validate((validate) =>{
                    if(validate){
                        alert("submit!");
                    }else {
                        this.$message.error("请输入所有字段");
                        return false;
                    }
                })
            }
        }

    }
</script>

<style scoped>
    .loginContainer{
        border-radius: 15px;
        background-clip:padding-box;
        margin: 180px auto;
        width: 350px;
        padding: 15px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;
    }
    .loginTitle{
        margin: 15px auto 20px auto;
        text-align: center;
        color: #505458;
    }
    .loginRember{
        text-align: left;
        margin: 0 0 25px 0;
    }
</style

登录页的浏览器效果如下图所示

:rules 校验规则 :model 表单里面的数据对象

                                                     觉得文章对自己有用,想要继续学下去的可以

                                                                         可以长按下方二维码        

                                                                

                                                                           关注【javalingfeng】哦

                                                          公众号正在更新vue.js和springboot的详细教程

                                                          还有超多免费Java,Python,Android等系列教程

                                                                                    等你来领

 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这是一个简单的Spring Boot + Vue前端分离项目,供您参考: 后端(Spring Boot): 1. 创建一个Spring Boot项目,添加Web和JPA依赖 2. 配置数据库连接信息 3. 创建实体类和对应的Repository接口 4. 创建Controller类,实现对应的API接口 前端(Vue): 1. 安装Vue CLI,创建一个Vue项目 2. 安装Axios,用于发送HTTP请求 3. 创建Vue组件,实现对应的页面功能 4. 在组件中使用Axios发送请求,获取后端数据 具体可以参考以下代码: 后端代码: 实体类: ``` @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; private String email; // getter和setter方法省略 } ``` Repository接口: ``` public interface UserRepository extends JpaRepository<User, Long> { } ``` Controller类: ``` @RestController @RequestMapping("/api") public class UserController { @Autowired private UserRepository userRepository; @GetMapping("/users") public List<User> getUsers() { return userRepository.findAll(); } } ``` 前端代码: 安装Axios: ``` npm install axios ``` Vue组件: ``` <template> <div> <h2>用户列表</h2> <table> <thead> <tr> <th>ID</th> <th>姓名</th> <th>邮箱</th> </tr> </thead> <tbody> <tr v-for="user in users" :key="user.id"> <td>{{ user.id }}</td> <td>{{ user.name }}</td> <td>{{ user.email }}</td> </tr> </tbody> </table> </div> </template> <script> import axios from 'axios'; export default { data() { return { users: [], }; }, mounted() { axios.get('/api/users').then((response) => { this.users = response.data; }); }, }; </script> ``` 以上代码仅供参考,具体实现可以根据自己的实际情况进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值