Login.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div class="login-wrap">
  3. <el-form
  4. class="login-from"
  5. label-position="top"
  6. label-width="80px"
  7. :model="fromData">
  8. <h2>用户登录</h2>
  9. <el-form-item label="用户名">
  10. <el-input v-model="fromData.UserName"></el-input>
  11. </el-form-item>
  12. <el-form-item label="密码">
  13. <el-input @keyup.enter.native="handleLogin" type="password" v-model="fromData.Password"></el-input>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button @click="handleLogin" class="btn" type="primary">登录</el-button>
  17. </el-form-item>
  18. </el-form>
  19. </div>
  20. </template>
  21. <script type="text/javascript">
  22. export default {
  23. data() {
  24. return {
  25. fromData: {
  26. UserName: '',
  27. Password: ''
  28. }
  29. };
  30. },
  31. methods: {
  32. async handleLogin () {
  33. const response = await this.$http.post(`keeper?action=login`, this.fromData);
  34. const { status, data:{ Message}} = response;
  35. // console.log(response)
  36. if (response.data.Code === 200) {
  37. this.$message.success('登录成功');
  38. // 将tocken取到
  39. const token = document.cookie;
  40. // console.log(token)
  41. // 将tocken保存到sessionStorage中
  42. sessionStorage.setItem('token', token);
  43. this.$router.push('/');
  44. } else {
  45. this.$message.error('登录失败');
  46. }
  47. },
  48. }
  49. };
  50. </script>
  51. <style scoped>
  52. .login-wrap{
  53. background-color: #324152;
  54. height: 100%;
  55. display: flex;
  56. justify-content: center;
  57. align-items: center;
  58. }
  59. .login-wrap .login-from{
  60. background-color: #fff;
  61. width: 400px;
  62. border-radius: 5px;
  63. padding: 30px;
  64. }
  65. .login-wrap .login-from .btn{
  66. width: 100%;
  67. }
  68. </style>