初学,遇到点小问题。配的接口到底是个啥,url怎么用的?
发布于 5 年前 作者 ofu 9023 次浏览 来自 官方Issues
//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    region: ['河南省', '南阳市', '宛城区'],
    realtim:' '
  },
  changeRegion: function (e) {
    this.setData({
      region: e.detail.value
      // e 的值换
    })
    this.getWeater();//更新天气
  },
  getWeater: function () {
    var that = this;//this不可以直接在wxAPI函数内部使用
    wx.request({
      url: 'http://apis.juhe.cn/simpleWeather/query',
      data: {
        location: that.data.region[1],
        key: 'f143fbc73add19906e230e6a73b0f821'
      },
      method: 'GET',
      success: function (res) {
        console.log(res.data)
        that.setData({ realtim: res.data.HeWeather6[0].realtim})
      }
    })
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: 'http://apis.juhe.cn/simpleWeather/query'
    })
  },

  // 生命周期函数--监听页面加载
  onLoad: function (options) {
    this.getWeater();
  },

  // 生命周期函数--监听页面初次渲染完成
  onReady: function () {

  },

  // 生命周期函数--监听页面显示
  onShow: function () {

  },

  // 生命周期函数--监听页面隐藏
  onHide: function () {

  },

  /**
 * 生命周期函数--监听页面卸载
 */
  onUnload: function () {

  },

//  页面相关事件处理函数--监听用户下拉动作
  onPullDownRefresh: function () {

  },

// 页面上拉触底事件的处理函数
  onReachBottom: function () {

  },

//  用户点击右上角分享
  onShareAppMessage: function () {

  }

})

2 回复

猜:天气接口

--↓↓👍点赞是回答的动力哦

回到顶部