uni-app中condition内的query参数无法获取

uni-app中condition内的query参数无法获取

操作步骤:

  • 运行至安卓基座

预期结果:

{product_id:71}

实际结果:

{}

bug描述:

"condition": { 
//模式配置,仅开发期间生效
"current": 0, //当前激活的模式(list 的索引项)
"list": [{
"name": "test", //模式名称
"path": "pages/sub-packages/cloud-class/cloud-detail", //启动页面,必选
"query":"product_id=71" //启动参数,在页面的onLoad函数里面得到
}]
}
无法获取query内的参数,模拟器及手机本体都无法获取
信息类别 信息内容
产品分类 uniapp/App
PC开发环境 Windows
PC开发环境版本 win7
HBuilderX类型 正式
HBuilderX版本 3.99
手机系统 Android
手机系统版本 Android 13
手机厂商 小米
手机机型 note11t pro
页面类型 vue
vue版本 vue3
打包方式 云端
项目创建方式 HBuilderX

更多关于uni-app中condition内的query参数无法获取的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

这种bug似乎也没人在意

更多关于uni-app中condition内的query参数无法获取的实战教程也可以访问 https://www.itying.com/category-93-b0.html


正常,我看好像也不是什么大bug。

同样取不到 诶

在 uni-app 中,condition 是用于配置小程序的启动页面的条件编译。condition 中的 query 参数可以在页面启动时通过 onLoad 生命周期函数中的 options 参数获取。如果你在 condition 中配置了 query 参数但无法获取,可能是以下原因导致的:


1. 检查 condition 配置

确保 pages.json 中的 condition 配置正确,且 query 参数已正确设置。例如:

{
  "condition": {
    "current": 0,
    "list": [
      {
        "name": "detail",
        "path": "pages/detail/detail",
        "query": "id=123&type=1"
      }
    ]
  }
}

2. 在页面中获取 query 参数

在目标页面(如 pages/detail/detail)的 onLoad 生命周期中,通过 options 获取 query 参数:

export default {
  onLoad(options) {
    console.log(options); // 输出 { id: '123', type: '1' }
    const { id, type } = options;
    console.log(id, type); // 输出 123 1
  }
}
回到顶部