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

MySQL data archiving tool mysql_archiver detailed explanation

Table of contents I. Overview 2. pt-archiver main...

Detailed process of Vue front-end packaging

Table of contents 1. Add packaging command 2. Run...

How to install MySQL under Linux (yum and source code compilation)

Here are two ways to install MySQL under Linux: y...

An Uncommon Error and Solution for SQL Server Full Backup

1. Error details Once when manually performing a ...

abbr mark and acronym mark

The <abbr> and <acronym> tags represen...

Solution to MySQL server login error ERROR 1820 (HY000)

Fault site: Log in to the MySQL server and get th...

A brief analysis of React's understanding of state

How to define complex components (class component...

MySQL tutorial thoroughly understands stored procedures

Table of contents 1. Concepts related to stored p...

IE6 implements min-width

First of all, we know that this effect should be ...

Detailed tutorial on installing Docker and nvidia-docker on Ubuntu 16.04

Table of contents Docker Installation Nvidia-dock...

How to configure tomcat server for eclipse and IDEA

tomcat server configuration When everyone is lear...

Vue implements sample code to disable browser from remembering password function

Find information Some methods found on the Intern...

Instance method for mysql string concatenation and setting null value

#String concatenation concat(s1,s2); concatenate ...