使用Vue.js和Element-UI做一個(gè)簡單登錄頁面的實(shí)例
最近了解到Vue.js挺火的,有同學(xué)已經(jīng)學(xué)習(xí)了,那我心里癢癢的也學(xué)習(xí)了一點(diǎn),然后也學(xué)了一點(diǎn)Element組件,就做了簡單的登錄頁面。
效果很簡單:

代碼如下:
前端頁面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" rel="external nofollow" >
<script type="text/javascript" src="vue/dist/vue.js"></script>
<script type="text/javascript" src="element-ui/lib/index.js"></script>
<script type="text/javascript" src="jquery/jquery-3.1.1.js"></script>
<style>
.el-row {
margin-bottom: 20px;
&:last-child {
margin-bottom: 0;
}
}
.login-box {
margin-top:20%;
margin-left:40%;
}
</style>
</head>
<body>
<div class="login-box" id="app" >
<el-row>
<el-col :span="8">
<el-input id="name" v-model="name" placeholder="請輸入帳號">
<template slot="prepend">帳號</template>
</el-input>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-input id="password" v-model="password" type="password" placeholder="請輸入密碼">
<template slot="prepend">密碼</template>
</el-input>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-button id="login" v-on:click="check" style="width:100%" type="primary">登錄</el-button>
</el-col>
</el-row>
</div>
</body>
<script type="text/javascript">
new Vue({
el : '#app',
data : {
name : '',
password : ''
},
methods : {
check : function(event){
//獲取值
var name = this.name;
var password = this.password;
if(name == '' || password == ''){
this.$message({
message : '賬號或密碼為空!',
type : 'error'
})
return;
}
$.ajax({
url : 'login',
type : 'post',
data : {
name : name,
password : password
},
success : function(data) {
var result = data.result;
if(result == 'true' || result == true){
alert("登錄成功");
}else {
alert("登錄失敗");
}
},
error : function(data) {
alert(data);
},
dataType : 'json',
})
}
}
})
</script>
</html>
后臺代碼:
package com.moson.backstage.controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* LoginController
* @author MoXingJian
* @email 939697374@qq.com
* @date 2017年6月20日 下午3:03:50
* @version 1.0
*/
@WebServlet("/login")
public class LoginController extends HttpServlet{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name");
String password = request.getParameter("password");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/xml;charset=UTF-8");
PrintWriter out = response.getWriter();
if(name.equals("MoSon") && password.equals("123456")){
out.write("{\"result\":true}");
}else{
out.write("{\"result\":false}");
}
out.flush();
out.close();
}
}
以上這篇使用Vue.js和Element-UI做一個(gè)簡單登錄頁面的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- vue.js使用Element-ui實(shí)現(xiàn)導(dǎo)航菜單
- vue.js+element-ui動態(tài)配置菜單的實(shí)例
- vue.js與element-ui實(shí)現(xiàn)菜單樹形結(jié)構(gòu)的解決方法
- vue.js element-ui tree樹形控件改iview的方法
- vue.js element-ui validate中代碼不執(zhí)行問題解決方法
- 使用element-ui +Vue 解決 table 里包含表單驗(yàn)證的問題
- Vue element-ui父組件控制子組件的表單校驗(yàn)操作
- 詳解element-ui 表單校驗(yàn) Rules 配置 常用黑科技
- vue.js+element-ui的基礎(chǔ)表單實(shí)例代碼
相關(guān)文章
vscode中開發(fā)運(yùn)行uniapp項(xiàng)目詳細(xì)步驟
VSCode作為一個(gè)非常強(qiáng)大的代碼編輯器,可以集成眾多的插件和工具來優(yōu)化開發(fā)效率,這篇文章主要給大家介紹了關(guān)于vscode中開發(fā)運(yùn)行uniapp項(xiàng)目的詳細(xì)步驟,需要的朋友可以參考下2023-07-07
Vue函數(shù)式組件的應(yīng)用實(shí)例詳解
這篇文章主要介紹了Vue函數(shù)式組件的應(yīng)用實(shí)例詳解,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08
Vue中filter使用及根據(jù)id刪除數(shù)組元素方式
這篇文章主要介紹了Vue中filter使用及根據(jù)id刪除數(shù)組元素方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
vue elementUI 表單嵌套驗(yàn)證的實(shí)例代碼
這篇文章主要介紹了vue + elementUI 表單嵌套驗(yàn)證,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11
vue3.0 的 Composition API 的使用示例
這篇文章主要介紹了vue3.0 的 Composition API 的使用示例,幫助大家更好的理解和學(xué)習(xí)vue,感興趣的朋友可以了解下2020-10-10
圖文講解用vue-cli腳手架創(chuàng)建vue項(xiàng)目步驟
本次小編給大家?guī)淼氖顷P(guān)于用vue-cli腳手架創(chuàng)建vue項(xiàng)目步驟講解內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2019-02-02

