Vue + element + 路由守卫 实现登录注册

该博客介绍了如何使用Vue.js、ElementUI和路由守卫实现用户注册和登录功能。内容包括登录页面布局、登录实现、路由守卫的配置,以及注意事项,如字段一致性、next参数的使用和登录状态验证。同时,提到了通过meta属性来判断路由是否需要登录。
摘要由CSDN通过智能技术生成

一、目标介绍

        · 实现注册用户账号

        · 完成登录后跳转主页面

         二、登录、注册、路由守卫

         三、注意事项

         四、界面效果


二、登录、注册、路由守卫

        2.1 登录页面布局

<template>
  <div class="login-section">
    <!-- :rules="rules" -->
    <el-form
      label-position="top"
      label-width="100px" class="demo-ruleForm"
      :rules="rules"
      :model="rulesForm"
      status-icon
      ref="ruleForm"
    >
      <el-form-item label="用户名" prop="name">
        <el-input type="text" v-model="rulesForm.name"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="rulesForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <el-button>重置</el-button>
      </el-form-item>
    </el-form>
  </div>
  
</template>

<style lang="stylus">
.login-section
  padding 0px 20px
</style>

 2.2 实现登录

<script>
import {login} from '@/service/api';

export default {
  data() {
    return {
      //存储数据的对象
      rulesForm:{
        name:'',
        password:''
      },
      rules:{
		  //自定义校检规则
        name:[
          {required:true,message:'名字',trigger:'blur'},
          {min:1,max:5,message:'长度在3到5',trigger:'blur'}
        ],
        password:[
          {required:true,message:'密码',trigger:'blur'},
          {min:3,max:5,message:'长度在3到5',trigger:'blur'}
  
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值