login.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <v-container class="login-page" fluid>
  3. <validation-observer ref="observer" v-slot="{ invalid }" slim>
  4. <v-form @submit.prevent="submit()">
  5. <validation-provider
  6. v-slot="{ errors }"
  7. ref="providerPhome"
  8. name="手机号码"
  9. rules="required|min:11|max:11"
  10. slim
  11. >
  12. <v-text-field
  13. v-model="form.phone"
  14. label="手机号"
  15. name="phone"
  16. required
  17. :error-messages="errors"
  18. placeholder="请输入"
  19. maxlength="11"
  20. type="tel"
  21. />
  22. </validation-provider>
  23. <validation-provider
  24. v-slot="{ errors }"
  25. ref="providerPassword"
  26. name="密码"
  27. rules="required"
  28. slim
  29. >
  30. <v-text-field
  31. v-model="form.password"
  32. label="密码"
  33. placeholder="请输入"
  34. name="phone"
  35. required
  36. :error-messages="errors"
  37. type="password"
  38. />
  39. </validation-provider>
  40. <div class="">
  41. <v-btn type="submit" :disabled="invalid" :loading="submitting"
  42. >login</v-btn
  43. >
  44. </div>
  45. </v-form>
  46. </validation-observer>
  47. </v-container>
  48. </template>
  49. <script>
  50. export default {
  51. auth: 'guest',
  52. name: 'LoginPage',
  53. data() {
  54. return {
  55. form: {
  56. phone: '',
  57. password: '',
  58. },
  59. submitting: false,
  60. };
  61. },
  62. methods: {
  63. async submit() {
  64. try {
  65. this.submitting = true;
  66. const valid = await this.$refs.observer.validate();
  67. if (valid) {
  68. await this.login(this.form);
  69. }
  70. } finally {
  71. this.submitting = false;
  72. }
  73. },
  74. async login(data) {
  75. await this.$auth.loginWith('password', data);
  76. },
  77. logout() {
  78. return this.$auth.logout();
  79. },
  80. },
  81. };
  82. </script>