wx.request中的请求参数data能不能做成动态的?

小程序 文章 2022-02-22 00:00 462 0 全屏看文

AI助手支持GPT4.0

wx.request中的请求参数data能不能做成动态的?Can the request parameter data in wx.request be made dynamic?

wx.request中的请求参数data能不能做成动态的?

data中的参数想从后台获取,是不是不能做成动态的?

onLoad: function () {   

wx.request({

      url: 'https://xxx.php ',

     data: that.data.key //这里动态获取参数(如果是当前页面 wx.request在onLoad 中默认加载用 一直不行,但是做成按钮手动调用是可行的)   

headers: {

        'Content-Type': 'application/json'

      },

      success: function (res) {

        s.setData({

          leiyisnei: res.data,

        })

    }

    })

}

求大神解答。。

The parameters in data want to be obtained from the background. Can't they be made dynamic? onLoad: function () { wx.request({ url: ' https://xxx.php ', data: that. data. Key / / get the parameters dynamically here (if the current page wx.request cannot be loaded by default in onload, but it is feasible to call it manually by making a button) headers: {content type ':'application / JSON'}, success: function (RES) {s.setdata ({leiyisnei: res.data,})}}} ask God for an answer..

回答:

微盟:

一般这种问题可能是你异步导致的,key值还没从另外一个接口拿到就开始用来调用这个接口了,建议使用链式调用

tomheng:

key 数据哪里来的, onLoad 的时候有数据吗

透明人丶M:

var that = this

是有的

-EOF-

AI助手支持GPT4.0