欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue實(shí)現(xiàn)登錄注冊(cè)模板的示例代碼

 更新時(shí)間:2021年04月01日 10:50:56   作者:~李疆  
這篇文章主要介紹了vue實(shí)現(xiàn)登錄注冊(cè)模板的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

模板1: 

login.vue

<template>
	<p class="login">
		<el-tabs v-model="activeName" @tab-click="handleClick">
			<el-tab-pane label="登錄" name="first">
				<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
					<el-form-item label="名稱" prop="name"><el-input v-model="ruleForm.name"></el-input></el-form-item>
 
					<el-form-item label="密碼" prop="pass"><el-input type="password" v-model="ruleForm.pass" auto-complete="off"></el-input></el-form-item>
 
					<el-form-item>
						<el-button type="primary" @click="submitForm('ruleForm')">登錄</el-button>
 
						<el-button @click="resetForm('ruleForm')">重置</el-button>
					</el-form-item>
				</el-form>
			</el-tab-pane>
 
			<el-tab-pane label="注冊(cè)" name="second">
				<register></register>
			</el-tab-pane>
		</el-tabs>
	</p>
</template>
 
<script>
import register from '@/components/register';
 
export default {
	data() {
		var validatePass = (rule, value, callback) => {
			if (value === '') {
				callback(new Error('請(qǐng)輸入密碼'));
			} else {
				if (this.ruleForm.checkPass !== '') {
					this.$refs.ruleForm.validateField('checkPass');
				}
 
				callback();
			}
		};
 
		return {
			activeName: 'first',
			ruleForm: {
				name: '',
				pass: '',
				checkPass: ''
			},
			rules: {
				name: [{ required: true, message: '請(qǐng)輸入您的名稱', trigger: 'blur' }, { min: 2, max: 5, message: '長(zhǎng)度在 2 到 5 個(gè)字符', trigger: 'blur' }],
				pass: [{ required: true, validator: validatePass, trigger: 'blur' }]
			}
		};
	},
 
	methods: {
		//選項(xiàng)卡切換
		handleClick(tab, event) {},
		//重置表單
		resetForm(formName) {
			this.$refs[formName].resetFields();
		},
		//提交表單
		submitForm(formName) {
			this.$refs[formName].validate(valid => {
				if (valid) {
					this.$message({
						type: 'success',
						message: '登錄成功'
					});
					this.$router.push('home');
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		}
	},
	components: {
		register
	}
};
</script>
 
<style lang="scss">
.login {
	width: 400px;
	margin: 0 auto;
}
 
.el-tabsitem {
	text-align: center;
	width: 60px;
}
</style>

register.vue

//register組件
 
<template>
	<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
		<el-form-item label="用戶名" prop="name"><el-input v-model="ruleForm.name"></el-input></el-form-item>
		<el-form-item label="密碼" prop="pass"><el-input type="password" v-model="ruleForm.pass" auto-complete="off"></el-input></el-form-item>
		<el-form-item label="確認(rèn)密碼" prop="checkPass"><el-input type="password" v-model="ruleForm.checkPass" auto-complete="off"></el-input></el-form-item>
		<el-form-item>
			<el-button type="primary" @click="submitForm('ruleForm')">注冊(cè)</el-button>
			<el-button @click="resetForm('ruleForm')">重置</el-button>
		</el-form-item>
	</el-form>
</template>
 
<script>
export default {
	data() {
		var validatePass = (rule, value, callback) => {
			if (value === '') {
				callback(new Error('請(qǐng)輸入密碼'));
			} else {
				if (this.ruleForm.checkPass !== '') {
					this.$refs.ruleForm.validateField('checkPass');
				}
				callback();
			}
		};
 
		var validatePass2 = (rule, value, callback) => {
			if (value === '') {
				callback(new Error('請(qǐng)?jiān)俅屋斎朊艽a'));
			} else if (value !== this.ruleForm.pass) {
				callback(new Error('兩次輸入密碼不一致!'));
			} else {
				callback();
			}
		};
 
		return {
			activeName: 'second',
			ruleForm: {
				name: '',
				pass: '',
				checkPass: ''
			},
			rules: {
				name: [{ required: true, message: '請(qǐng)輸入您的名稱', trigger: 'blur' }, { min: 2, max: 5, message: '長(zhǎng)度在 2 到 5 個(gè)字符', trigger: 'blur' }],
				pass: [{ required: true, validator: validatePass, trigger: 'blur' }],
				checkPass: [{ required: true, validator: validatePass2, trigger: 'blur' }]
			}
		};
	},
 
	methods: {
		submitForm(formName) {
			this.$refs[formName].validate(valid => {
				if (valid) {
					this.$message({
						type: 'success',
						message: '注冊(cè)成功'
					});
					// this.activeName: 'first',
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
 
		resetForm(formName) {
			this.$refs[formName].resetFields();
		}
	}
};
</script>

效果圖

模板2:

 

login.vue

<template>
  <el-row type="flex" justify="center">
   <el-form ref="formData" :model="formData" :rules="rules" label-width="80px" @keyup.enter.native="login()">
    <el-form-item prop="userName" label="用戶名"><el-input v-model="formData.userName" placeholder="請(qǐng)輸入用戶名" prefix-icon="icon-login_user" clearable></el-input></el-form-item>
    <el-form-item prop="password" label="密碼"><el-input v-model="formData.password" placeholder="請(qǐng)輸入密碼" type="password" prefix-icon="icon-login_pwd" clearable></el-input></el-form-item>
    </el-form-item>
    <el-form-item><el-button type="primary" class="btn" @click="login('formData')" icon="el-icon-upload">登錄</el-button>
     <el-button @click="resetForm('formData')">重置</el-button></el-form-item></el-form-item>
     <router-link to="register">沒(méi)有密碼?注冊(cè)</router-link>
   </el-form>
  </el-row>
</template>
<script>
export default {
 data() {
  return {
   formData: {
    userName: '',
    password: ''
   },
   rules: {
    userName: [{ required: true, message: '用戶名不能為空', trigger: 'blur' }],
    password: [{ required: true, message: '密碼不能為空', trigger: 'blur' }]
   }
  };
 },
 methods: {
  login(formName) {
 
    this.$refs[formName].validate(valid => {
				if (valid) {
					this.$message({
						type: 'success',
						message: '登錄成功'
          });
           this.$router.push({name:'home'});
				} else {
					console.log('error submit!!');
					return false;
				}
			});
  },
   resetForm(formName) {
			this.$refs[formName].resetFields();
		}
 }
};
</script>

register.vue

<template>
  <el-row type="flex" justify="center">
   <el-form ref="formData" :model="formData" :rules="rules" label-width="80px" @keyup.enter.native="register()">
    <el-form-item prop="userName" label="用戶名"><el-input v-model="formData.userName" placeholder="請(qǐng)輸入用戶名" prefix-icon="icon-login_user" clearable></el-input></el-form-item>
    <el-form-item prop="password" label="密碼"><el-input v-model="formData.password" placeholder="請(qǐng)輸入密碼" type="password" prefix-icon="icon-login_pwd" clearable></el-input></el-form-item>
    <el-form-item prop="cheackPassword" label="確認(rèn)密碼"><el-input v-model="formData.cheackPassword" placeholder="再次輸入密碼" type="password" prefix-icon="icon-login_pwd" clearable></el-input></el-form-item>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="register('formData')" icon="el-icon-upload">注冊(cè)</el-button>
      <el-button @click="resetForm('formData')">重置</el-button></el-form-item>
     <router-link to="login">已有密碼?登錄</router-link>
 
   </el-form>
  </el-row>
</template>
<script>
export default {
 data() {
   var validatePass = (rule, value, callback) => {
			if (value === '') {
				callback(new Error('請(qǐng)?jiān)俅屋斎朊艽a'));
			} else if (value !== this.formData.password) {
				callback(new Error('兩次輸入密碼不一致!'));
			} else {
				callback();
			}
		};
 
  return {
   formData: {
    userName: '',
    password: '',
    cheackPassword:''
   },
   rules: {
    userName: [{ required: true, message: '用戶名不能為空', trigger: 'blur' }],
    password: [{ required: true, message: '密碼不能為空', trigger: 'blur' }],
    cheackPassword: [{ required: true, validator: validatePass, trigger: 'blur' }]
 
   }
  };
 },
 methods: {
  register(formName) {
   this.$refs[formName].validate(valid => {
				if (valid) {
					this.$message({
						type: 'success',
						message: '注冊(cè)成功'
          });
           this.$router.push({name:'login'});
				} else {
					console.log('error submit!!');
					return false;
				}
			});
  },
  resetForm(formName) {
			this.$refs[formName].resetFields();
		}
 
 }
};
</script>

效果圖

到此這篇關(guān)于vue實(shí)現(xiàn)登錄注冊(cè)模板的示例代碼的文章就介紹到這了,更多相關(guān)vue 登錄注冊(cè)模板內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解Vue的列表渲染

    詳解Vue的列表渲染

    這篇文章主要為大家介紹了Vue的列表渲染,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • 詳解關(guān)于vue-area-linkage走過(guò)的坑

    詳解關(guān)于vue-area-linkage走過(guò)的坑

    這篇文章主要介紹了詳解關(guān)于vue-area-linkage走過(guò)的坑,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • 一文詳解如何在vue中實(shí)現(xiàn)文件預(yù)覽功能

    一文詳解如何在vue中實(shí)現(xiàn)文件預(yù)覽功能

    很多Vue項(xiàng)目中都需要PDF文件預(yù)覽功能,比如合同ERP,銷售CRM,內(nèi)部文檔CMS管理系統(tǒng),內(nèi)置PDF文件在線預(yù)覽功能,下面這篇文章主要給大家介紹了關(guān)于如何在vue中實(shí)現(xiàn)文件預(yù)覽功能的相關(guān)資料,需要的朋友可以參考下
    2022-10-10
  • vue+animation動(dòng)畫實(shí)現(xiàn)跑馬燈效果

    vue+animation動(dòng)畫實(shí)現(xiàn)跑馬燈效果

    這篇文章主要為大家詳細(xì)介紹了vue+animation動(dòng)畫實(shí)現(xiàn)跑馬燈效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • vue實(shí)現(xiàn)簡(jiǎn)單的MVVM框架

    vue實(shí)現(xiàn)簡(jiǎn)單的MVVM框架

    這篇文章給大家分享了基于vue實(shí)現(xiàn)一個(gè)簡(jiǎn)單的MVVM框架的相關(guān)內(nèi)容,有需要的朋友們可以參考學(xué)習(xí)下。
    2018-08-08
  • vue 不使用select實(shí)現(xiàn)下拉框功能(推薦)

    vue 不使用select實(shí)現(xiàn)下拉框功能(推薦)

    這篇文章主要介紹了vue 不使用select實(shí)現(xiàn)下拉框功能,在文章給大家提到了vue select 組件的使用與禁用,需要的朋友可以參考下
    2018-05-05
  • vue中實(shí)現(xiàn)頁(yè)面刷新以及局部刷新的方法

    vue中實(shí)現(xiàn)頁(yè)面刷新以及局部刷新的方法

    這篇文章主要給大家介紹了關(guān)于vue中實(shí)現(xiàn)頁(yè)面刷新以及局部刷新的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-01-01
  • Vue之el-select結(jié)合v-if動(dòng)態(tài)控制template顯示隱藏方式

    Vue之el-select結(jié)合v-if動(dòng)態(tài)控制template顯示隱藏方式

    這篇文章主要介紹了Vue之el-select結(jié)合v-if動(dòng)態(tài)控制template顯示隱藏方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • vue3+ts+vant移動(dòng)端H5項(xiàng)目搭建的實(shí)現(xiàn)步驟

    vue3+ts+vant移動(dòng)端H5項(xiàng)目搭建的實(shí)現(xiàn)步驟

    本文主要介紹了vue3+ts+vant移動(dòng)端H5項(xiàng)目搭建,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • vue 公共列表選擇組件,引用Vant-UI的樣式方式

    vue 公共列表選擇組件,引用Vant-UI的樣式方式

    這篇文章主要介紹了vue 公共列表選擇組件,引用Vant-UI的樣式方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11

最新評(píng)論