cdn引入vue形式的url参数获取方法

 //获取url参数
            get_query_string: function(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg); //search,查询?后面的参数,并匹配正则
                if (r != null) return decodeURI(r[2]);
                return null;
            },
   //设置cookie
            setCookie(cname, cvalue, exdays) {
                var d = new Date();
                d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
                var expires = "expires=" + d.toUTCString();
                document.cookie = cname + "=" + cvalue + "; " + expires;
            },
 
            //获取cookie
            getCookie(cname) {
                var name = cname + "=";
                var ca = document.cookie.split(";");
                for (var i = 0; i < ca.length; i++) {
                    var c = ca[i];
                    while (c.charAt(0) == " ") c = c.substring(1);
                    if (c.indexOf(name) != -1) {
                        return c.substring(name.length, c.length);
                    }
                }
                return "";
            },
            //清除cookie
            clearCookie(cname) {
                this.setCookie(cname, "", -1);
            }

 

posted @ 2020-09-10 13:53  net开发人员  阅读(724)  评论(0编辑  收藏  举报