uniapp隐藏参数

H5获取参数后移除浏览器的显示

920 发布: 2025/6/16 08:06 本文总阅读量

携带参数跳转,完毕后隐藏参数-主要针对H5

// 在页面的onLoad生命周期中调用此函数
onLoad(options) {
    // 处理接收到的参数
    this.handleTab(options.tab)
    // 移除URL中的参数
    this.removeUrlParam('tab')
},

methods: {
    handleTab(tab) {
        // 处理tab参数的逻辑
        console.log('当前tab:', tab)
    },

    removeUrlParam(paramKey) {
        const currentUrl = window.location.href
        const urlObj = new URL(currentUrl)

        // 如果URL中存在该参数,则移除它
        if (urlObj.searchParams.has(paramKey)) {
            
            urlObj.searchParams.delete(paramKey)
            // 使用HTML5的history API更新URL,不会触发页面刷新
            window.history.replaceState(null,document.title,urlObj.toString())
        }
    }
}