获取路由参数 getUrlParam
1.封装
var self = { getUrlParam(search = "", key) { var param = []; var result = ""; if (search.length > 0) { if (search.indexOf("&&") == -1) { param = search.split("?")[1].split("&"); } else { param = search.split("?")[1].split("&&"); } for (var i = 0; i < param.length; i++) { if (param[i].indexOf(key + "=") != -1) { result = param[i].split("=")[1]; break; } } } return result; }, }; module.exports = self;
2.调用
import func from "UTIL/commonFunc"; let id = func.getUrlParam(location.search, "id");
.