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)
}
})
}
本文来自博客园,作者:jialiangzai,转载请注明原文链接:https://www.cnblogs.com/zsnhweb/articles/18145953

浙公网安备 33010602011771号