欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vue项目中获取cdn域名插件

程序员文章站 2023-04-07 19:52:37
import axios from 'axios' let CdnPath = {} CdnPath.install = function (Vue, options) { Vue.prototype.$_cdnDomain = function () { if (process.env.NODE_... ......
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