微信小程序switchTab传参以及接收参数

wx.switchTab({ url: /yb_mingpian/pages/newIndex/newIndex?is_first_login=1, });

这样的传参方式是不行的

解决方法:

我们可以在switch跳转之前设置一个全局变量,到下一个页面的时候,直接去获取全局变量

index.js 保存参数先

wx.request({
            url: "http://127.0.0.1:5000/wx_login",
            method: POST,
            data: e.detail.value,
            success: function (res) {
                // console.log(res.data);
                if (res.data.status == 1) {
                    wx.showToast({
                        title: "登录成功",
                        icon: "success",
                        duration: 3000
                    })
                    getApp().globalData.md_username = res.data.wx_username,  //登录用户名
                    getApp().globalData.md_store = res.data.store,  //门店
                    getApp().globalData.md_level = res.data.level,  //等级
                    getApp().globalData.md_greetings = res.data.greetings,  //问候语
                    wx.switchTab({
                        url: ../contact/contact,
                    })
                } else {
                    wx.showToast({
                        title: "账号或密码不对",
                        icon: "none",
                        duration: 3000
                    })
                }
            }
        })

contact.js 获取参数

/**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.setNavigationBarTitle({
            title: getApp().globalData.md_greetings
        })

    },
经验分享 程序员 微信小程序 职场和发展