Vue 獲取URL鏈接后面的參數值


PC端如以下地址獲取ptypeorderId的值

http://localhost:20472//AppWeb/ToPay?ptype=2&orderId=e6c1f659-94cd-4e4d-b7c9-56b3c8a7a8d6

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

  笨辦法用在了手機端

mounted() {
            //http://localhost:8080/#/order/Payresult?orderCode=20200721093517378188743943022
            var url = window.location.href ; //獲取url中"?"符后的字串       
            var cs = url.split('?')[1];                //獲取?之后的參數字符串
            //alert(url+'地址');//orderCode=20200721093517378188743943022
            var cc ='';
            var cs2 = '';
            if (cs.length > 0)
            {
                cs = cs.replace('orderId=', '');
                var cc =cs.split('&')[0];//獲取orderid
                var cs1 = cs.split('&')[1];//ocd=20200818103843816416953617735
                var cs2 = cs1.replace('ocd=', '');//20200818103843816416953617735
            }
            this.oid = cc;
            this.orderCode = cs2;
        } 

====一勞永逸的方法===================
getUrlKey(name){//獲取url 參數
return decodeURIComponent(
(new RegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)').exec(location.href)||[,""])[1].replace(/\+/g,'%20'))||null;
}

引用:
this.getUrlKey(ptype)



 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM