login.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. name: 'LoginPage',
  50. data() {
  51. return {
  52. form: {
  53. phone: '17600000010',
  54. password: '1234567890',
  55. },
  56. submitting: false,
  57. };
  58. },
  59. methods: {
  60. async submit() {
  61. try {
  62. this.submitting = true;
  63. const valid = await this.$refs.observer.validate();
  64. if (valid) {
  65. await this.login(this.form);
  66. }
  67. } finally {
  68. this.submitting = false;
  69. }
  70. },
  71. async login(data) {
  72. await this.$auth.loginWith('password', data);
  73. },
  74. logout() {
  75. return this.$auth.logout();
  76. },
  77. },
  78. };
  79. </script>