LoginForm.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <div id="login-form">
  3. <h2>Login</h2>
  4. <input
  5. type="email"
  6. name="email"
  7. v-model="email"
  8. placeholder="Email"
  9. >
  10. <input
  11. type="password"
  12. name="password"
  13. v-model="password"
  14. placeholder="Password"
  15. >
  16. <button
  17. type="button"
  18. name="login"
  19. @click.stop="onLogin"
  20. >
  21. login
  22. </button>
  23. </div>
  24. </template>
  25. <script>
  26. import { mapState, mapActions } from 'vuex'
  27. export default {
  28. name: "LoginForm",
  29. data: () => ({
  30. email:null,
  31. password:null
  32. }),
  33. methods: {
  34. ...mapActions({
  35. userLogin: 'User/userLogin'
  36. }),
  37. onLogin () {
  38. this.userLogin({
  39. mail: this.email,
  40. pass: this.password
  41. }).then( () => {
  42. console.log('logedin from login component');
  43. this.$emit('onLogedIn')
  44. }
  45. ).catch(( error ) => {
  46. console.warn('Issue with login from login component', error)
  47. Promise.reject(error)
  48. })
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. </style>