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.

main.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* eslint-disable prefer-template */
  2. import Vue from 'vue';
  3. import EvaIcons from 'vue-eva-icons';
  4. import axios from 'axios';
  5. import App from './App.vue';
  6. import router from './router';
  7. import store from './store';
  8. Vue.use(EvaIcons);
  9. Vue.config.productionTip = false;
  10. Vue.prototype.$http = axios;
  11. const token = localStorage.getItem('token');
  12. if (token) {
  13. Vue.prototype.$http.defaults.headers.common.Authorization = token;
  14. }
  15. router.beforeEach((to, from, next) => {
  16. if (to.matched.some(record => record.meta.requiresAuth)) {
  17. if (store.getters.isLoggedIn) {
  18. next();
  19. return;
  20. }
  21. next('/users/login');
  22. } else {
  23. next();
  24. }
  25. });
  26. Vue.filter('toCurrency', (value) => {
  27. if (typeof value !== 'number') {
  28. return value;
  29. }
  30. const formatter = new Intl.NumberFormat('en-US', {
  31. minimumFractionDigits: 2,
  32. });
  33. return `R ${formatter.format(value)}`;
  34. });
  35. Vue.filter('toProper', (value) => {
  36. if (typeof value !== 'string') {
  37. console.log(typeof value);
  38. return value;
  39. }
  40. value = value.replace(/([a-z])([A-Z])/g, '$1 $2');
  41. return value.charAt(0).toUpperCase() + value.slice(1);
  42. });
  43. Vue.filter('toDate', value => value.substring(0, value.length > 9 ? 10 : value.length));
  44. new Vue({
  45. render: h => h(App),
  46. router,
  47. store,
  48. }).$mount('#app');