vue项目中获取cdn域名插件

import axios from 'axios'
let CdnPath = {}
CdnPath.install = function (Vue, options) {
    Vue.prototype.$_cdnDomain = function () {
        if (process.env.NODE_ENV === 'production') {
            sessionStorage.setItem('cdnPath', 'https://cdn.hhhhaaaa.com');
        } else {
            sessionStorage.setItem('cdnPath', 'https://hhhh.aaaa.com.cn');
        }
    }();
    Vue.prototype.$_cPath = function (path) {
        const reg = /^(http|ftp|https):\/\//;
        const regStatic = /^static\//;
        if (!path) {
            return ''
        } else {
            if (!reg.test(path)) {
                if (regStatic.test(path)) {
                    return path
                }
                let cdnDomain = sessionStorage.getItem('cdnPath');
                if (cdnDomain !== null) {
                    return cdnDomain + path
                }
                return path
            }
            return path
        }
    }
}
export default CdnPath

 


posted @ 2019-03-22 14:54  林玖女神  阅读(860)  评论(0编辑  收藏  举报