login.vue 1.8 KB

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