Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. window.axios = require('axios');
  2. Vue.use(Framework7Vue);
  3. Vue.component('page-about', require('./components/mobile/AboutComponent.vue'));
  4. new Vue({
  5. el: '#app',
  6. framework7: {
  7. root: '#app',
  8. animateNavBackIcon: true,
  9. swipePanel: 'right',
  10. routes: [
  11. {
  12. path: '/about/',
  13. component: 'page-about'
  14. }
  15. ],
  16. },
  17. data: function () {
  18. return {
  19. loginMessage: null,
  20. isLogin: false,
  21. profile: null,
  22. loginUsername: null,
  23. loginPassword: null
  24. }
  25. },
  26. methods: {
  27. login: function () {
  28. var v = this;
  29. axios.post(process.env.MIX_APP_URL + '/api/auth/login', {
  30. username: this.loginUsername,
  31. password: this.loginPassword
  32. })
  33. .then(function (response) {
  34. if(response.data.token) {
  35. v.loginMessage = "ورود با موفقیت انجام شد. کمی صبر کنید...";
  36. localStorage.setItem('token', response.data.token);
  37. axios.post(process.env.MIX_APP_URL + '/api/user',{token:response.data.token}).then(function(response){v.profile = response.data.user;}).catch(function (error){});
  38. v.isLogin = true;
  39. v.$f7.closeModal();
  40. } else {
  41. v.loginMessage = "اطلاعات وارد شده اشتباه است.";
  42. }
  43. })
  44. .catch(function (error) {
  45. v.loginMessage = "خطا در ارتباط با شبکه";
  46. });
  47. },
  48. logout: function() {
  49. var v = this;
  50. v.isLogin = false;
  51. localStorage.removeItem("token");
  52. }
  53. },
  54. //computed: {
  55. mounted:function () {
  56. var v = this;
  57. if(localStorage.getItem("token")) {
  58. axios.post(process.env.MIX_APP_URL + '/api/user',{token:localStorage.getItem("token")}).then(function(response){v.profile = response.data.user;}).catch(function (error){});
  59. v.isLogin = true;
  60. return v.profile;
  61. } else {
  62. v.isLogin = false;
  63. }
  64. }
  65. //}
  66. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement