UNPKG

cheetah-framework

Version:

Cheetah Framework JS used in all our applications

40 lines (30 loc) 788 B
/** * This plugin add url helpers to Vue instances. */ import config from '@cheetah/config' export default { install: function (Vue) { Vue.prototype.$rootUrl = function (path = '') { const basePath = _.trimEnd(_.get(window.Cheetah, 'appUrl', ''), '/') if (!path) { return basePath } return mergePath(basePath, path) } Vue.prototype.$assetUrl = function (asset) { return mergePath(this.$rootUrl(), config.assetDir, asset) } } } function mergePath (...paths) { return _.reduce(paths, (fullPath, segment) => { if (!fullPath) { return segment } segment = _.trimEnd(segment, '/ ') if (_.startsWith(segment, '/')) { return fullPath + segment } return fullPath + '/' + segment }, '') }