uniapp实现刷新页面保留参数页面不报错的情况

let refreshHan = () => {
    // 获取当前页面的实例
    const pages = getCurrentPages()
    const currentPage = pages[pages.length - 1]
    // 获取页面路径和参数
    const {
        route,
        options
    } = currentPage
    let urlWithParams = `/${route}?`
    for (const key in options) {
        const value = options[key]
        urlWithParams += `${key}=${value}&`
    }
    urlWithParams = urlWithParams.slice(0, -1) // 去除最后的"&"
    // 使用 uni.redirectTo 或 uni.reLaunch 方法刷新页面并传入参数
    uni.reLaunch({
        url: urlWithParams,
        success: () => {
            console.log('页面刷新成功', urlWithParams)
        },
        fail: (err) => {
            console.error('页面刷新失败', err)
        }
    })
}
posted @ 2024-04-19 15:15  jialiangzai  阅读(125)  评论(0)    收藏  举报