Last active
January 2, 2020 16:49
-
-
Save Gkiokan/0440cc5a4ff2b62d757af161d510f776 to your computer and use it in GitHub Desktop.
Vue Util
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Author: Gkiokan Sali | |
Date: 02.01.2020 | |
Notes: Utility for Vue JS functions, used as this.$util.{functionName} | |
*/ | |
import Vue from 'vue' | |
import moment from 'moment' | |
let util = { | |
data: { | |
loader: false, | |
}, | |
getFormatedPrice(value){ | |
return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(value) | |
}, | |
getPriceValue(item){ | |
let preis = item.visum_preis.toString().replace(',', '.') // parseFloat(item.preis) | |
return preis | |
}, | |
getDate(val){ | |
if(!val) return; | |
return moment(val).format('DD.MM.Y') | |
}, | |
today(){ | |
return moment().format('YYYY-MM-DD') | |
}, | |
todayUTC(){ | |
return moment().toDate().toISOString() | |
}, | |
startLoader(){ | |
if(!this.data.loader) | |
this.data.loader = Vue.$loading.show(); | |
}, | |
stopLoader(){ | |
if(this.data.loader && typeof this.data.loader.hide == 'function') | |
this.data.loader.hide() | |
// else | |
// console.log(this.data.loader.hide) | |
this.data.loader = false | |
}, | |
randomInt(min, max) { | |
return Math.floor(Math.random() * (max - min + 1) + min); | |
}, | |
buildQuery(obj){ | |
let x = Object.entries(obj) | |
.map(pair => pair.map(encodeURIComponent).join('=')) | |
.join('&'); | |
return x | |
}, | |
getHostName(){ | |
let e = window.config.env | |
let h = window.location.host | |
if(e && e.value) | |
return e.value | |
return h | |
} | |
} | |
Vue.prototype.$util = util |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment