wx.getLaunchOptionsSync()獲取小程序啟動時的參數:
path 啟動小程序的路徑
scene 啟動小程序的場景值
query 啟動小程序的 query 參數
shareTicket shareTicket,詳見獲取更多轉發信息
referrerInfo 來源信息。從另一個小程序、公眾號或 App 進入小程序時返回。否則返回 {}。
// 啟動參數為1個的時候,案例如下,僅供自己后續復習:
let launchRes = wx.getLaunchOptionsSync() // 以下是業務邏輯,不同情況業務邏輯不同 if (launchRes.path === 'pages/house/house' && 'Id' in launchRes.query && launchRes.query.Id) { const Id = launchRes.query.Id wx.setStorageSync('Id', Id) }
// 啟動參數多個時,案例如下,僅供自己后續復習:
let launchRes = wx.getLaunchOptionsSync()
console.log('小程序啟動參數---', launchRes)
if (launchRes.path === 'moduleRole/pages/moreDetail/moreDetail' && 'scene' in launchRes.query && launchRes.query.scene) {
const scene = decodeURIComponent(launchRes.query.scene)
let reportId = ''
if (scene.indexOf('&') !== -1) {
const sceneArr = scene.split('&')
this.setState({
reportId: sceneArr[0]
})
reportId = sceneArr[0]
} else {
this.setState({
reportId: scene
})
reportId = scene
}
}