从公众号消息进入小程序,调用onShow方法,第二次进入还是第一次的数据?
发布于 6 年前 作者 chaozhu 5147 次浏览 来自 官方Issues
// app.js
onShow(options) {
        console.log(options, 'app');
        let queryObj = options.query
        this.globalData.isLoading = false
        this.globalData.business_product_id = queryObj.business_product_id ? queryObj.business_product_id : ''
        this.globalData.repayment_wx_trade_no = queryObj.repayment_wx_trade_no ? queryObj.repayment_wx_trade_no : ''
        console.log(this.globalData.business_product_id);
        console.log(this.globalData.repayment_wx_trade_no);
    },
// index.js
const app = getApp();
const PRODUCT_ID = parseInt(app.globalData.business_product_id)
const TRADE_NO = app.globalData.repayment_wx_trade_no

onShow() {
        // 返回判断不用执行函数
        if (app.globalData.isLoading) {
            return
        }
        console.log(TRADE_NO);
        this.judgeEvent(TRADE_NO)
    },

    // 判断执行函数
    judgeEvent(TRADE_NO) {
        console.log(TRADE_NO);
        if (TRADE_NO) {
            console.log(TRADE_NO, 'trade');
            this.getRepayment(paySuccess.url, paySuccess.params)
        } else {
            console.log(PRODUCT_ID, 'product');
            this.getRepayment(payParams.url, payParams.params)
        }
    },

// 比如第一次this.getRepayment(paySuccess.url, paySuccess.params),但是第二次获取不同发参数,
// 实际执行this.getRepayment(payParams.url, payParams.params),但还是第一次的数据
回到顶部