SignUpComponent.vue
2.43 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<template>
<div>
<v-row
align="center"
justify="center"
>
<v-col
cols="12"
sm="8"
md="4"
>
<v-card>
<v-form v-model="valid" @submit.prevent="signUp">
<v-card-text>
<v-text-field
v-model="email"
:rules="[rules.email]"
prepend-icon="email"
label="email">
</v-text-field>
<v-text-field
v-model="username"
:rules="[rules.username]"
prepend-icon="person"
label="username">
</v-text-field>
<v-text-field
v-model="password"
:rules="[rules.password]"
prepend-icon="lock"
type="password"
label="password">
</v-text-field>
<v-text-field
v-model="checkpassword"
:rules="[rules.checkpassword]"
prepend-icon="lock"
type="password"
label="checkpassword">
</v-text-field>
</v-card-text>
<v-card-actions>
<v-spacer/>
<v-btn
color="yellow"
type="submit">
회원가입
</v-btn>
</v-card-actions>
</v-form>
</v-card>
</v-col>
</v-row>
</div>
</template>
<script>
export default {
name: "SignUpComponent",
data() {
return {
valid: false,
email: '',
name: '',
password: '',
checkpassword: '',
rules: {
email: v => (v || '').match(/@/) || 'Please enter a valid email',
username: v => !!v || 'usrename is required',
password: v => !!v || 'password is required',
checkpassword: v => v == this.password || 'checkpassword is incorrect'
}
}
},
methods: {
async signUp() {
try {
console.log('signUp Method');
//$store.dispatch -> action의 signUp 함수를 불러올 수 있음
await this.$store.dispatch('user/signUp', {
email: this.email,
username: this.username,
password: this.password
});
await this.$router.replace('/');
} catch (e) {
console.error(e);
}
}
}
}
</script>
<style scoped>
</style>