家政小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <style lang="less">
  2. </style>
  3. <template>
  4. <Modal v-model="show">
  5. <p slot="header">
  6. <Icon type="information-circled"></Icon>
  7. <span>请登录</span>
  8. </p>
  9. <div>
  10. <Form ref="form" :label-width="80">
  11. <FormItem label="用户名">
  12. <Input v-model="username" />
  13. </FormItem>
  14. <FormItem label="密码">
  15. <Input v-model="password" />
  16. </FormItem>
  17. </Form>
  18. </div>
  19. <div slot="footer">
  20. <Button type="primary" @click="login">登录</Button>
  21. </div>
  22. </Modal>
  23. </template>
  24. <script>
  25. import Cookies from 'js-cookie';
  26. export default {
  27. name: 'login',
  28. data() {
  29. return {
  30. show: false,
  31. username: '',
  32. password: ''
  33. }
  34. },
  35. methods: {
  36. login() {
  37. this.axios.post("login", {
  38. name: this.username,
  39. password: this.password
  40. }).then((res) => {
  41. if (res.data.status === 0) {
  42. Cookies.set('user', this.username);
  43. Cookies.set('token', res.data.token);
  44. if (res.data.role == "admin") {
  45. Cookies.set("access", 1);
  46. } else {
  47. Cookies.set("access", 0);
  48. }
  49. this.axios.defaults.headers.common['Authorization'] = "Bearer " + res.data.token;
  50. this.show = false;
  51. }
  52. });
  53. }
  54. }
  55. }
  56. </script>