Vue Login Form Component

Account Login


<template>
<div>
<slot></slot>
<el-form
class="account-form-container"
status-icon
:ref="loginFormRef"
:model="loginForm"
:rules="loginRules">
<!-- <el-form-item label="用户名" label-width="80px"> -->
<el-form-item prop="username">
<span class="form-item-label">用户名</span>
<el-input
type="text"
v-model="loginForm.username"
@change="usernameChange"
class="account-form-input"
autocomplete="off"
placeholder="请输入用户名"
maxlength="8"
aria-placeholder="">
<i slot="prefix" class="el-icon-user"></i>
</el-input>
</el-form-item>
<!-- <el-form-item label="密码" label-width="0px"> -->
<el-form-item prop="password">
<span class="form-item-label">密码</span>
<el-input
data-type="password"
type="password"
show-password
v-model="loginForm.password"
@change="passwordChange"
maxlength="12"
class="account-form-input"
autocomplete="off"
placeholder="请输入密码"
aria-placeholder="">
<i slot="prefix" class="el-icon-lock"></i>
</el-input>
</el-form-item>
<el-form-item>
<el-button
type="primary"
style="width: 100%;"
@click="submit">
提交
</el-button>
</el-form-item>
<el-form-item>
<el-button
type="default"
style="width: 100%;"
@click="reset(`loginFormRef`)">
重置
</el-button>
</el-form-item>
</el-form>
</div>
</template> <script>
const log = console.log;
export default {
name: "AccountLogin",
components: {},
props: {
name: {
type: String,
required: false,
default: "",
},
loginFormRef: {
type: String,
required: true,
// default: {},
},
loginForm: {
type: Object,
required: true,
// default: {},
},
loginRules: {
type: Object,
required: true,
// default: {},
},
},
// data: function () {return {};}
data() {
return {
loading: false,
data: [],
// form: {
// username: '',
// password: '',
// },
};
},
watch: {
name: {
// Run as soon as the component loads
immediate: true,
handler() {
// Set the 'componentname' value as props
this.componentname = this.name;
},
},
},
methods: {
fetchAPI(url = ``) {
// this.data = [];
log(`fetch url`, url);
},
usernameChange(value) {
log(`username =`, value);
},
passwordChange(value) {
log(`password =`, value);
},
submit() {
const {
username,
password,
} = this.loginForm;
// } = this.$props.loginForm;
// } = this.$data.form;
// } = this.form;
// 对整个表单验证
this.$refs.loginFormRef.validate((valid, other) => {
log(`valid, other`, valid, other)
if (valid) {
this.$emit(`successCallback`, ` awesome`);
} else {
this.$emit(`errorCallback`, ` holy shit`);
}
})
log(`username, password =`, username, password);
// if(username === "admin" && password === `1234567`) {
// this.$message({
// message: '登录成功消息 ',
// type: 'success',
// customClass: "message-class",
// duration: 0,
// showClose: true,
// });
// // this.$message.success('登录成功消息 !');
// } else {
// this.$message({
// message: '登录失败消息 ',
// type: 'error',
// customClass: "message-class",
// });
// // this.$message.error(' 出错了!');
// }
},
reset(formRefName) {
// clear
this.loginForm.username = ``;
this.loginForm.password = ``;
// reset
this.$refs[formRefName].resetFields();
},
},
beforeCreate() {
log(`beforeCreate`, 1);
},
created() {
log(`created`, 2);
},
beforeMount() {
log(`beforeMount`, 3);
},
mounted() {
log(`mounted`, 4);
},
beforeUpdate() {
log(`beforeUpdate`, 5);
},
updated() {
log(`updated`, 6);
},
beforeDestroy() {
log(`beforeDestroy`, 7);
},
destroyed() {
log(`destroyed`, 8);
},
}
</script> <style scope lang="scss">
.account-form-container {
box-sizing: border-box;
/* width: 500px; */
/* border: 1px solid red; */
padding: 10px;
}
.form-item-label{
display: inline-block;
width: 100%;
text-align: left;
}
.form-item-label::after{
content: " :";
}
.message-class{
padding: 10px;
min-width: 352px;
}
</style>

Phone Login



demo


<template>
<div>
<div>
<account-login
@successCallback="successCallback"
@errorCallback="errorCallback"
:loginFormRef="loginFormRef"
:loginForm="loginForm"
:loginRules="loginRules">
<h1>Account Login Form</h1>
</account-login>
</div>
<div>
<phone-login>
<h1>Phone Login Form</h1>
</phone-login>
</div>
</div>
</template> <script>
const log = console.log; import AccountLogin from "@/components/AccountLogin";
import PhoneLogin from "@/components/PhoneLogin";
export default {
name: "Login",
components: {
AccountLogin,
PhoneLogin,
},
props: {
name: {
type: String,
required: false,
default: "",
},
},
// data: function () {return {};}
data() {
// const usernameChecker = (rule, value, callback) => {
// if (!value) {
// return callback(new Error(' 用户名不能为空'));
// }
// if (this.loginFormRef.username !== '') {
// this.$refs.loginFormRef.validateField('username');
// }
// callback();
// }
// const passwordChecker = (rule, value, callback) => {
// if (!value) {
// return callback(new Error(' 密码不能为空'));
// }
// if (this.loginFormRef.password !== '') {
// this.$refs.loginFormRef.validateField('password');
// }
// callback();
// }
return {
loading: false,
data: [],
loginFormRef: "loginFormRef",
loginForm: {
username: ``,
password: ``,
},
loginRules: {
username: [
{
required: true,
message: "用户名不可为空!",
trigger: "blur",
},
{
min: 4,
max: 8,
message: "用户名长度为 4 ~ 8 个字符!",
trigger: "blur",
},
// {
// validator: usernameChecker,
// // regex validation
// trigger: "blur",
// },
],
password: [
{
required: true,
message: "密码不可为空!",
trigger: "blur",
},
{
min: 6,
max: 12,
message: "用户名长度为 6 ~ 12 个字符!",
trigger: "blur",
},
// {
// validator: passwordChecker,
// // regex validation
// trigger: "blur",
// },
],
},
};
},
methods: {
fetchAPI(url = ``) {
// this.data = [];
log(`fetch url`, url);
},
successCallback(value) {
log(`success callback =`, value);
this.$message({
message: `登录成功消息 ${value}`,
type: 'success',
customClass: "message-class",
duration: 0,
showClose: true,
});
},
errorCallback(error) {
log(`error callback =`, error);
this.$message({
message: `登录失败消息 ${error}`,
type: 'error',
customClass: "message-class",
});
},
},
beforeCreate() {
log(`beforeCreate`, 1);
},
created() {
log(`created`, 2);
},
beforeMount() {
log(`beforeMount`, 3);
},
mounted() {
log(`mounted`, 4);
},
beforeUpdate() {
log(`beforeUpdate`, 5);
},
updated() {
log(`updated`, 6);
},
beforeDestroy() {
log(`beforeDestroy`, 7);
},
destroyed() {
log(`destroyed`, 8);
},
}
</script> <style scope lang="scss">
.className {
color: #000;
background: #fff;
}
</style>

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


Vue Login Form Component的更多相关文章

  1. 第六章 组件 59 组件切换-使用Vue提供的component元素实现组件切换

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  2. vue中extend/component/mixins/extends的区别

    vue中extend/component/mixins/extends的区别 教你写一个vue toast弹窗组件 Vue.extend构造器的延伸

  3. how can I make the login form transparent?

    This is how you can make the Login Form transparent: 1. Add this css to Server Module-> Custom cs ...

  4. [Angular] Implement a custom form component by using control value accessor

    We have a form component: <label> <h3>Type</h3> <workout-type formControlName=& ...

  5. vue 组件复用 - component

    vue 组件复用 - component vue 组件复用 就是对 component 标签的使用 先看图 下图看使用 结果: 可以看到 在箱包 这一项,我将banner 组件用了两次,我 每次 点击 ...

  6. 关于vue使用form上传文件

    在vue中使用form表单上传文件文件的时候出现了一些问题,获取文件的时候一直返回null, 解决之后又出现发送到后台的file文件后台显示为空,解决源码 <template> <d ...

  7. vue el-upload form 同时提交

    项目需要form 表单和文件上传同时在一个请求,废话不多说上代码: 上传的组件使用pug格式 .row.my-4 .col-12 el-form(:model='domain', :rules='va ...

  8. vue elementui form表单验证

    最近我们公司将前端框架由easyui 改为 vue+elementui .自学vue两周 就开始了爬坑之路.业余时间给大家分享一下心得,技术新手加上第一次分享(小激动),有什么不足的地方欢迎大家指正, ...

  9. [Firebase] 3. Firebase Simple Login Form

    Using $firebaseSimpleLogin service. Here we use three methods for login, logout, register and getCur ...

随机推荐

  1. 都知道Base64,Base32你能实现吗?

    很长时间没有更新个人博客了,因为前一段时间在换工作,入职了一家新的公司,刚开始需要适应一下新公司的节奏,开始阶段也比较忙.新公司还是有一定的技术气氛的,每周都会有技术分享,而且还会给大家留一些思考题, ...

  2. JavaScript中的迭代器和生成器[未排版]

    JavaScript中的迭代器 在软件开发领域,"迭代"的意思是按照顺序反复多次执行一段程序,通常会有明确的终止条件. ECMAScript 6规范新增了两个高级特性:迭代器和生成 ...

  3. 为什么MySQL索引使用B+树

    为什么MySQL索引使用B+树 聚簇索引与非聚簇索引 不同的存储引擎,数据文件和索引文件位置是不同的,但是都是在磁盘上而不是内存上,根据索引文件.数据文件是否放在一起而有了分类: 聚簇索引:数据文件和 ...

  4. Mybatis参数预编译

    Mybatis参数预编译 一.数据库预编译介绍 1.数据库SQL语句编译特性: 数据库接受到sql语句之后,需要词法和语义解析,优化sql语句,制定执行计划.这需要花费一些时间.但是很多情况,我们的一 ...

  5. git的使用学习笔记---合并分支

    一.使用场景 不同的分支需要合并 二.操作 1.首先要创建一个分支 git checkout -b mergedemo 创建文本 vim text.txt 添加文本 git add text.txt ...

  6. logging philosophy 日志哲学

    Go kit - Frequently asked questions https://gokit.io/faq/ Logging - Why is package log so different? ...

  7. Map类型数据导出Excel--poi

    https://blog.csdn.net/KevinChen2019/article/details/101064790 <dependency> <groupId>org. ...

  8. LOJ10069 TREE

    题目描述 原题来自:2012 年国家集训队互测 给你一个无向带权连通图,每条边是黑色或白色.让你求一棵最小权的恰好有 need 条白色边的生成树.题目保证有解. 输入格式 第一行 V,E,need 分 ...

  9. slowhttptest慢速攻击工具使用详解

    参考文章 浅谈"慢速HTTP攻击Slow HTTP Attack" HTTP慢速攻击 Slowhttptest攻击原理 InstallationAndUsage tag: #slo ...

  10. Flutter GetX使用---简洁的魅力!

    前言 使用Bloc的时候,有一个让我至今为止十分在意的问题,无法真正的跨页面交互!在反复的查阅官方文档后,使用一个全局Bloc的方式,实现了"伪"跨页面交互,详细可查看:flutt ...