LoginView.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <div id="main">
  3. <div id="form">
  4. <el-form :model="form" label-width="120px" @keyup.enter.native="onSubmit">
  5. <el-form-item :label="lang.account">
  6. <el-input v-model="form.account" placeholder="User Name" />
  7. </el-form-item>
  8. <el-form-item :label="lang.password">
  9. <el-input v-model="form.password" placeholder="Password" type="password" />
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button type="primary" @click="onSubmit">{{ lang.login }}</el-button>
  13. </el-form-item>
  14. </el-form>
  15. </div>
  16. </div>
  17. </template>
  18. <script setup>
  19. import { reactive } from 'vue'
  20. import $http from "../http/http";
  21. import { ElMessage } from 'element-plus'
  22. import router from "@/router"; //根路由对象
  23. import lang from '../i18n/i18n';
  24. const form = reactive({
  25. account: '',
  26. password: '',
  27. })
  28. const onSubmit = () => {
  29. $http.post("/api/login", form).then(res => {
  30. if (res.errorNo != 0) {
  31. ElMessage.error(res.errorMsg)
  32. } else {
  33. router.replace({
  34. path: '/',
  35. query: {
  36. redirect: router.currentRoute.fullPath
  37. }
  38. })
  39. }
  40. })
  41. }
  42. </script>
  43. <style scoped>
  44. #main {
  45. width: 100%;
  46. height: 100%;
  47. background-color: #f1f1f1;
  48. display: flex;
  49. justify-content: center;
  50. /* 水平居中 */
  51. align-items: center;
  52. /* 垂直居中 */
  53. }
  54. </style>