Element-Plus在进行reactive在对登录用户密码输入输入时失效最后发现是<elform>,在进行refmodel进行绑定时候绑定属性名称都是一致的,导致界面无法输入,如下图所示绑定的是:loginForm,代码下图所示

<template>
  <el-form
    :model="loginForm"
    ref="loginForm"
    label-position="left"
    label-width="0px"
    class="demo-ruleForm login-container"
  >
    <span class="tool-bar"> </span>
    <h2 class="title" style="padding-left: 22px">系统登录</h2>
    <el-form-item prop="account">
      <el-input
        type="text"
        v-model="loginForm.account"
        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-form-item>
          <el-col :span="12">
            <el-form-item prop="captcha">
              <el-input
                type="test"
                v-model="loginForm.captcha"
                auto-complete="off"
                placeholder="验证码, 单击图片刷新"
                style="width: 100%"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col class="line" :span="1">&amp;nbsp;</el-col>
          <el-col :span="11">
            <el-form-item>
              <img
                style="width: 100%"
                class="pointer"
                :src="loginForm.src"
                @click="refreshCaptcha"
              />
            </el-form-item>
          </el-col>
        </el-form-item> -->
    <el-form-item style="width: 100%">
      <el-button type="primary" style="width: 48%" @click="reset"
        >重 置</el-button
      >
      <el-button
        type="primary"
        style="width: 48%"
        @click="dologin"
        :loading="loading"
        >登 录</el-button
      >
    </el-form-item>
  </el-form>
</template>
<script setup>
import { reactive,ref } from "vue";
import { Login } from "../../../apis/login/login.js";

// 用户登录信息
let loading=false;
const test=ref("");
const loginForm =reactive({
  account: "",
  password: "",
});
//重置
function reset() {
  loginForm.account = "";
  loginForm.password = "";
  return "";
}
function dologin(loginForm) {
  let data = Login(loginForm);
  console.log(data);
  return data;
}
</script>
<style  scoped>
/* .myform {
  width: 200px;
  height: 180px;
  text-align: center;
  margin-right: 20px;
  background-color: #050;
} */
.login-container {
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 100px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    /* box-shadow: 0 0 25px #cac6c6;
    .title {
      margin: 0px auto 30px auto;
      text-align: center;
      color: #505458;
    } */
  }
</style>

此时界面操作输入框,是无法编辑的:

而<el-form>修改model=”loginForm”,ref=”loginForm”,确保两个引用名称不一致,否则会导致界面无法预览界面输入框操作恢复正常,修改后的代码截图如下: 

<template>
  <el-form
    :model="loginForm"
    ref="loginForm"
    label-position="left"
    label-width="0px"
    class="demo-ruleForm login-container"
  >
    <span class="tool-bar"> </span>
    <h2 class="title" style="padding-left: 22px">系统登录</h2>
    <el-form-item prop="account">
      <el-input
        type="text"
        v-model="loginForm.account"
        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-form-item>
          <el-col :span="12">
            <el-form-item prop="captcha">
              <el-input
                type="test"
                v-model="loginForm.captcha"
                auto-complete="off"
                placeholder="验证码, 单击图片刷新"
                style="width: 100%"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col class="line" :span="1">&amp;nbsp;</el-col>
          <el-col :span="11">
            <el-form-item>
              <img
                style="width: 100%"
                class="pointer"
                :src="loginForm.src"
                @click="refreshCaptcha"
              />
            </el-form-item>
          </el-col>
        </el-form-item> -->
    <el-form-item style="width: 100%">
      <el-button type="primary" style="width: 48%" @click="reset"
        >重 置</el-button
      >
      <el-button
        type="primary"
        style="width: 48%"
        @click="dologin"
        :loading="loading"
        >登 录</el-button
      >
    </el-form-item>
  </el-form>
</template>
<script setup>
import { reactive,ref } from "vue";
import { Login } from "../../../apis/login/login.js";

// 用户登录信息
let loading=false;
const test=ref("");
const loginForm =reactive({
  account: "",
  password: "",
});
//重置
function reset() {
  loginForm.account = "";
  loginForm.password = "";
  return "";
}
function dologin(loginForm) {
  let data = Login(loginForm);
  console.log(data);
  return data;
}
</script>
<style  scoped>
/* .myform {
  width: 200px;
  height: 180px;
  text-align: center;
  margin-right: 20px;
  background-color: #050;
} */
.login-container {
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 100px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    /* box-shadow: 0 0 25px #cac6c6;
    .title {
      margin: 0px auto 30px auto;
      text-align: center;
      color: #505458;
    } */
  }
</style>

原文地址:https://blog.csdn.net/veceny/article/details/129474566

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_25690.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注