Example of implementing login effect with vue ElementUI's from form

Example of implementing login effect with vue ElementUI's from form

1. Build basic styles through ElementUI

If you don’t know ElementUI, please visit the official website https://element.eleme.cn/#/zh-CN to get a basic understanding of ElementUI.

1.1 Use of ElementUI First install ElementUI in the project through the command npm i element-ui S

1.2 Then find the from form on the official website and then you can do the basic layout

So here is the framework I have written

<el-form
      label-position="top"
      label-width="100px" class="demo-ruleForm"
      :rules='rules'
      :model='rulesForm'
      status-icon
      ref='ruleForm'
    >
        <el-form-item label="username" prop="name">
            <el-input type="text" v-model="rulesForm.name"></el-input>
        </el-form-item>
 
        <el-form-item label="password" 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')">Submit</el-button>
            <el-button>Reset</el-button>
        </el-form-item>
    </el-form>

The effects of these codes

Some ElementUI properties are used here, so I won’t explain them here. They are all on the official website. So I’ll put some screenshots for you to check these properties.

Then the rules and model are used together to make some input boxes to enter rules

Then bind these two rules to the account and password box

ElementUI layout is just a few clicks

2. Click the Submit button to pass the contents of the account and password box to the background data

We can better get the attributes in the tag through ref

The following is the method to pass the content in the input box to the background

methods: {
    submitForm(fromName){
      this.$refs[fromName].validate((valid)=>{
          if(valid){
            //If the check passes, send the username and password to the backend login({
              name:this.rulesForm.name,
              password:this.rulesForm.password
            }).then((data)=>{
              if(data.code==0){
                localStorage.setItem('token',data.data.token)
                window.location.href='/'
              }
              if(data.code==1){
                this.$message.error(data.message)
              }
            })
          }else{
            console.log('error submit!!')
            return false
          }
      })
    }
  }

One of them is login, which is a method obtained by encapsulating an interface of the backend

This method is bound to the submit button

Then we enter the existing account password and click the submit button to log in.

Then we render some login information

Summarize

There are two steps to achieve a login effect: first use ElementUI to build the corresponding style --- "Click the submit button to pass the content in the account and password box to the background data

This is the end of this article about the example of using vue ElementUI's from form to achieve login effects. For more relevant vue Element from form login content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • An example of using Vue.js and Element-UI to make a simple login page
  • vue+Element-ui implements login registration form
  • How to use vue+element ui to realize a good-looking login interface

<<:  Complete steps for using Nginx+Tomcat for load balancing under Windows

>>:  Analysis of the difference between Mysql InnoDB and MyISAM

Recommend

A brief discussion on the role of Vue3 defineComponent

Table of contents defineComponent overload functi...

A brief discussion on React Component life cycle functions

What are the lifecycle functions of React compone...

Detailed explanation of the usage of scoped slots in Vue.js slots

Table of contents No slots Vue2.x Slots With slot...

How to find out uncommitted transaction information in MySQL

A while ago, I wrote a blog post titled "Can...

Linux system disk formatting and manually adding swap partition

Windows: Support NTFS, FAT Linux supports file fo...

Steps to configure IIS10 under Win10 and support debugging ASP programs

Microsoft IIS IIS (Internet Information Server) i...

Let's talk about the two functions of try catch in Javascript

The program is executed sequentially from top to ...

TinyEditor is a simple and easy-to-use HTML WYSIWYG editor

A few days ago, I introduced to you a domestic xh...

Detailed explanation of :key in VUE v-for

When key is not added to the v-for tag. <!DOCT...

Summary of solutions for MySQL not supporting group by

I downloaded and installed the latest version of ...

The perfect solution for forgetting the password in mysql8.0.19

Recommended reading: MySQL 8.0.19 supports accoun...

How to hide rar files in pictures

You can save this logo locally as a .rar file and...

Native js imitates mobile phone pull-down refresh

This article shares the specific code of js imita...

How to install and configure the Apache Web server

Learn how to host your own website on Apache, a r...