login.vue
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
<div id="login_box">
<el-row type="flex" justify="center" align="middle" style="height:80%">
<el-card class="box-card" shadow="hover" style="width:25%">
<div slot="header" style="text-align:center" class="clearfix">
<span style="font-size:24px">合同管理系统</span>
</div>
<el-form ref="login_form" :model="form" :rules="rules" label-width="60px" label-position="top">
<el-form-item prop="username">
<el-input v-model="form.username">
<template slot="prepend">姓名</template>
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input type="password" v-model="form.password" auto-complete="off">
<template slot="prepend">密码</template>
</el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('login_form')">提交</el-button>
<el-button @click="resetForm('login_form')">重置</el-button>
</el-form-item>
</el-form>
</el-card>
</el-row>
</div>
</template>
<script>
export default {
name: "login",
data() {
return {
form: {
username: "",
password: ""
},
rules: {
username: [
{ required: true, message: "请输入用户名", trigger: "blur" }
],
password: [
{ required: true, message: "请输入登录密码", trigger: "blur" }
]
}
};
},
methods: {
submitForm(form) {
this.$refs[form].validate(valid => {
if (valid) {
console.log(valid);
console.log(this.form.username);
console.log(this.form.password);
window.localStorage.setItem("username", this.form.username);
window.sessionStorage.setItem("loginCheck", true);
window.sessionStorage.setItem("username", this.form.username);
this.$router.push({ path: "/nav/search" });
}
});
},
resetForm(form) {
this.$refs[form].resetFields();
}
},
mounted() {
this.form.username = localStorage.getItem("username");
},
};
</script>
<style scoped>
#login_box {
height: 100%
}
</style>