收藏
回答

函数间传值

我有一个疑问,同一个js里,函数之间怎么传值,感觉怎么都传不过去,难受想哭

回答关注问题邀请回答
收藏

41 个回答

  • 2018-04-13

    好的,非常感谢

    2018-04-13
    有用
    回复
  • 睡前原谅一切
    睡前原谅一切
    2018-04-13

    大兄弟 发代码来吧。。。。尴尬。

    2018-04-13
    有用
    回复
  • 2018-04-12

    不是很懂,大兄弟,不瞒你说,我其实是学机械的,能不能稍微帮我写一段,我试到现在还是没成功...不胜感激

    2018-04-12
    有用
    回复
  • 睡前原谅一切
    睡前原谅一切
    2018-04-12

    你的data没定义

    2018-04-12
    有用
    回复
  • 2018-04-12

    其实你所说的第一个方法我也试了...也没成功,不知道错在哪里...

    2018-04-12
    有用
    回复
  • 睡前原谅一切
    睡前原谅一切
    2018-04-12
    写两个方法。第一个方法调用成功的回调里 调用第二个方法 第一个方法里 存一下 token。第二个方法里使用 this.data.token 即可拿到token
    2018-04-12
    有用
    回复
  • 2018-04-12

    谢谢,我试试,比我快好多

    2018-04-12
    有用
    回复
  • 2018-04-12




    图片清楚点,我想把第一个request取的token用到第二个request里,打印出来是有的,但是传不到第二个函数里

    2018-04-12
    有用
    回复
  • 睡前原谅一切
    睡前原谅一切
    2018-04-12
      testone: function(e) {
          var token;
          var that = this;
          wx.request({
            method: 'POST',
            url: 'https://www.bigiot.net/oauth/token', //仅为示例,并非真实的接口地址           
            data: {
              client_id: "186",
              client_secret: "77d1d8d3ee",
              username: "3942",
              password: "23d3ea0544",
              grant_type: "password"
            },
            header: {
              'content-type': 'application/json' // 默认值     
            },
            success: function(res) {
              console.log(res.data)
              token = res.data.access_token;
              console.log(token)
            }
          })
          wx.request({
            method: 'POST',
            url: 'https://www.bigiot.net/oauth/say',
            data: {
              access_token: token,
              id: "5119",
              c: "play",
              sign: "首条",
            },
            header: {
              'content-type': 'application/json' // 默认值     
            },
            success: function(res) {
              console.log(res.data)
            }
          })
    }


    把你要设置数据 存到 data里   this.setData({ token: res.data.token })

    2018-04-12
    有用
    回复
  • 2018-04-12

    testone: function (e) {    var token;    var that = this ;    wx.request({      method: 'POST',      url: 'https://www.bigiot.net/oauth/token', //仅为示例,并非真实的接口地址            data: {        client_id: "186",        client_secret: "77d1d8d3ee",        username: "3942",        password: "23d3ea0544",        grant_type: "password"      },      header: {        'content-type': 'application/json' // 默认值      },      success: function (res) {        console.log(res.data)        token = res.data.access_token;              console.log(token)      }    })      wx.request({      method: 'POST',      url: 'https://www.bigiot.net/oauth/say',      data: {        access_token: token,        id: "5119",        c: "play",        sign: "首条",      },      header: {        'content-type': 'application/json' // 默认值      },      success: function (res) {        console.log(res.data)      }    })  },

    2018-04-12
    有用
    回复

正在加载...

登录 后发表内容