The value returned by a method of WeChat Mini Programs in util is empty.

Util in

WeChat Mini Programs has a function that takes a value in storage and returns it, which can be printed. However, the value returned is empty

.

Util.js

function get_user_info(){
    wx.getStorage({
            key : "user_info",
            success:function(data){
            // 
                console.log(data.data)
                return data.data
            },
            fail:function(res){
                console.log(""+res.errMsg)
            }
        })
  }

another called page print:

console.log(Util.get_user_info())
undefined



use promise, or wx.getStorageSync

Menu