点击button重新请求数据如何实现?
发布于 5 年前 作者 ping71 9685 次浏览 来自 问答

改变URl重新获取数据如何实现?

 wx.request({
      url: ‘’,
      data: {},
      method: ‘GET’,
      header: {      
        ‘content-type’: ‘application/json’
              }, // 设置请求的 header
      success: function(res){
        that.setData({
         servicePrice:res.data.result
        })  
      },
      fail: function() {
      },
      complete: function() {
      }
    })

是否通过this.setdata?

1 回复
var that = this;
wx.request({
      url: '',
      data: {},
      method: 'GET',
      header: {     
        'content-type': 'application/json'
              }, // 设置请求的 header
      success: function(res){
        that.setData({
         servicePrice:res.data.result
        }) 
      },
      fail: function() {
      },
      complete: function() {
      }
    })

你的servicePrice应该在Page里面的data中对应,这样就可以在WXML中实现动态绑定

回到顶部