How did Mini Program set global variables after a successful app.js network request had no effect?

problem description

I have a pop-up component, and I define a global variable isBgWindow in app.js to control whether it is displayed or not. But when I successfully change the isBgWindow, pop-up window component through the wx.requst request, it is not controlled. The novice solution

the environmental background of the problems and what methods you have tried

Mar.05,2022

is the cause of asynchrony. Hang isBgWindow on the parent component tag, such as

//
<group-component isBgWindow="{{isBgWindow}}"></group-components>
//
Component({
    /**
     * 
     */
    properties: {
        isBgWindow: {
            type: Boolean,
            value: 0,
            observer: function (newVal, oldVal, changedPath) {

            }
        },
    },
    ready: function() {
        let isBgWindow = this.data.isBgWindow;
        console.log(isBgWindow);
    },
})

here's how I handle it: the wx.login method app.js can be called by the parent component, and there is a callback to the parent component, which is passed to the child component


found something called userInfoReadyCallback, that you can use to call the data returned by app.js on other pages


1. The component must be applied in Page before you can decide to render. Declare in the page .json file that your component uses useComonents to register your component on the page, otherwise it will not render.
2. And Mini Program does not trigger redrawing in the same way as Vue, but may be a bit like react using this.setData to change data.

Menu