function sendRequest(path, data, callback) {
wx.request({
url: path,
data: data,
header: { 'content-type': 'application/json'
},
method: "POST",
success: callback,
fail:(res)=>{
console.log(res)
}
})
} 把微信请求封装起来
还有项目里面要用到的接口如下<img class="lazyload inited loaded" src="https://user-gold-cdn.xitu.io/2018/5/29/163aa029f634fd62?imageView2/0/w/1280/h/960/format/webp/ignore-error/1" alt=""><span style="font-size: 14px;">把接口暴露出去在其他页面调用</span><img class="lazyload inited loaded" src="https://user-gold-cdn.xitu.io/2018/5/29/163aa029fd54632f?imageView2/0/w/1280/h/960/format/webp/ignore-error/1" alt=""><img class="lazyload inited loaded" src="https://user-gold-cdn.xitu.io/2018/5/29/163aa02a044519ed?imageView2/0/w/1280/h/960/format/webp/ignore-error/1" alt=""><p><span style="max-width:90%">相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!</span></p><p><span style="font-size: 14px;">推荐阅读:</span></p><p><span style="font-size: 14px;">微信小程序开发怎样创建项目</span><br></p><p><span style="font-size: 14px;">微信小程序开发怎样编写代码</span><br></p><p>以上就是微信小程序开发中怎样实现数据交互的详细内容,更多请关注其它相关文章!</p>