获取url指定参数值(js/vue)

function getParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
}


vue中

方法一:

this.$route.query.xxx  //只要是在url里用?拼接的都可以

方法二:

getParam function(paramName) { 
    return decodeURIComponent((new RegExp('[?|&]' +
      paramName + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/+/g, '%20')) || null
}
原文地址:https://www.cnblogs.com/linjiangxian/p/11466087.html