zoukankan      html  css  js  c++  java
  • 使用api获取数据————小程序

    使用api获取数据————小程序

    onLoad: function (options) {  //打开页面即执行。
        let that = this;
        wx.request({       //建立链接
          url: 'http://web.juhe.cn:8080/constellation/getAll', //api获取的地址
          data: {
            consName: "巨蟹座",  //给api传输的数据
            type: "today",      //给api传输的数据
            key: app.globalData.constKey, //apiKey,没钥匙人家就不会给你数据了。
          },
          header: {
            'content-type': 'application/json'  //请求头,没头这哪成啊!!!
          },
          success(res) {  //请求成功!!
            console.log(res.data)  //请求成功,就让它告诉我一些呗,顺便看看数据有些啥,后面好操作。
            that.setData({
              number: res.data.number,  //获取想要的数据,和定义那些数据。
              all: res.data.all,       //这些数据定义完就可以直接使用了。
            })
          }
        })
      },
    

    具体说明写在备注上了。

    wx.request和ajax,axios的原理都是一样,可以类比过去。

  • 相关阅读:
    面向对象-01
    网络编程-02-客户端搭建
    网络编程-01-服务端搭建
    日志-02
    日志-01
    md5加密
    shell 第五天
    shell第四天
    shell第三天
    shell
  • 原文地址:https://www.cnblogs.com/cth0/p/11564447.html
Copyright © 2011-2022 走看看