当前位置: 移动技术网 > IT编程>开发语言>JavaScript > vue项目中获取cdn域名插件

vue项目中获取cdn域名插件

2019年03月23日  | 移动技术网IT编程  | 我要评论
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

 



                    

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网