要叫我三金吗 2021-07-06 14:37 采纳率: 50%
浏览 253
已采纳

Vue编写的登录界面

使用rules的表单验证检测是否为空,username和code都可以检测空,但是password不可以,都是一样写的,不知道为啥不行。

<template>
  <div>
    <el-form :rules="rules" ref="loginForm" :model="loginForm" class="loginContainer">
      <h3 class="loginTitle">系统登录</h3>
      <el-form-item prop="username">
        <el-input type="text" v-model="loginForm.username" autocomplete="false" placeholder="Please enter username" class="loginUser"></el-input>
      </el-form-item>
      <el-from-item prop="pwd">
        <el-input type="password" v-model="loginForm.pwd" autocomplete="false" placeholder="Please enter password" class="loginPassword"></el-input>
      </el-from-item>
      <el-form-item prop="code">
        <el-input type="text" v-model="loginForm.code" autocomplete="false" placeholder="Please enter identifying code" class="loginIdentify"></el-input>
        <img src="capthcaurl">
      </el-form-item>
      <el-form-item>
        <el-checkbox v-model="checked" class="loginRemeber">Remeber me</el-checkbox>
        <el-button type="primary" style="width:100%" @click="submitLogin">Login</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data: function () {
    return {
      captchaurl: '',
      loginForm: {
        username: 'admin',
        pwd: '123456',
        code: ''
      },
      checked: true,
      rules: {
        username: [{required: true, message: '请输入用户名', trigger: 'blur'}],
        pwd: [{required: true, message: '请输入密码', trigger: 'blur'}],
        code: [{required: true, message: '请输入验证码', trigger: 'blur'}]
      }
    }
  },
  methods: {
    submitLogin: function () {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style>
.loginContainer{
  border-radius: 15px;
  background-clip: padding-box;
  margin: 180px auto;
  width: 350px;
  padding: 15px 35px 15px 35px;
  background: #ffffff;
  border: 1px solid #eaeaea;
  box-shadow:0 0 25px #cac6c6;
}
.loginTitle{
  margin:0px auto 5px auto;
  text-align: center;
}
.loginPassword{
  margin: 0px auto 20px auto
}
.loginUser{
  margin: 5px auto 0px auto
}
.loginIdentify{
  width:250px;
  margin-right:5px;
}
.loginRemeber{
  margin-top:0px;
  margin-bottom: 15px;
}
</style>
  • 写回答

5条回答 默认 最新

  • hzx-web 2021-07-06 16:47
    关注

    写代码从不看报错吗?看一下控制台错误:
    img

    看你的代码:单词form写成了from,控制台也有报错
    <el-form-item> 写成: <el-from-item>
    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line