![](https://i-blog.csdnimg.cn/blog_migrate/a92159c053369365483b1a59047e2186.png)
先看上方扫码成功后的返回,根据返回进行如下代码操作,详解看注释
uni.scanCode({
success: function (res) {
var parts = res.path.split("?")
var pathname = parts[0] //跳转的路径
var params = {}; //携带的参数
if (parts.length > 1) {
var queryString = parts[1];
//通过&符将多个参数分割成数组
//例:比如完整路径是 company/JobList?id=1&position_id=50
//处理后结果为['id=1','position_id=50']
var queryParams = queryString.split("&");
//遍历这个数组,以对象形式将属性名和属性值存入到上面定义的params中
queryParams.forEach(function (param) {
var paramParts = param.split("=");
params[paramParts[0]] = paramParts[1];
});
}
//根据携带的参数名已经参数值做对应操作
if (params["id"]) {
uni.navigateTo({
url: '/' + pathname + '?id=' + params["id"]
})
}
if (params["position_id"]) {
uni.navigateTo({
url: '/' + pathname + '?position_id=' + params["position_id"]
})
}
}
});