vue3完整的登录页面,element-plus

发布时间:2024年01月19日

<template>
    <div class="login">
                <el-card class="box-card">
                    <el-form ref="form" :rules="rules" :model="forms" label-width="120px">
                         <el-form-item prop="user" label="用户名:">
                            <el-input v-model="forms.user" />
                        </el-form-item>
                        <el-form-item prop="password" label="密码:">
                               <el-input v-model="forms.password" />
                        </el-form-item>
                        <el-form-item>
                        <el-button type="primary" @click="onSubmit">Create</el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
    </div>
</template>
<script setup lang="ts">
import { ref,reactive } from 'vue';
import type {FromItemRules,FormInstance} from "element-plus"

// do not use same name with ref
interface Iform{
        user:string;
        password:string;
}
const forms = reactive<Iform>({
  user: '',
  password:'',
})
type Iroles={
      [k in keyof Iform]?:Array<FromItemRules>
}
const rules = reactive<Iroles>({
     user:[
        {
          required:true,
          message:"请输入用户名",
          type:"string",
          trigger:"change"
     }],
     password:[
        {
            required:true,
            message:"请输入密码",
            type:"string",
            trigger:"change"
        }
     ]    
})
const form = ref<FormInstance>();
const onSubmit = () => {
  console.log('submit!')
  form.value?.validate((validate:boolean)=>{
      console.log(validate)
  })
}
</script>
<style scoped>
.login{
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction:row;
      justify-content: center;
      align-items: center;
}
    
</style>
    

文章来源:https://blog.csdn.net/2302_79777012/article/details/135704593
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。