微信小程序wx.request后台数据交互

记录测试微信小程序wx.request这个api在跟后台交互时的DEMO。

test.js文件:

Page({
  data: {
  
  },
  onLoad: function () {
    var that = this//不要漏了这句,很重要
    wx.request({
      url: 'https://www.pulaiwang.com/api-zhuanpu_info-id-132729.html',
      headers: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        //将获取到的json数据,存在名字叫data_arr的这个数组中
        that.setData({
          data_arr: res.data,
          //res代表success函数的事件对,data是固定的
        })
      }
    })
  }
})

test.wxml文件

<text>{{data_arr.info.dianpu_title}}</text>

发表评论

邮箱地址不会被公开。 必填项已用*标注