一个网络请求, 可以获取ip地址, 看下面代码
Page({
data: {
ip: ''
},
onLoad: function () {
this.getapi();
},
getapi:function(){
var _this = this;
// 获取IP地址
wx.request({
url: 'https://tianqiapi.com/ip/',
data: {
},
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
console.log(res);_this.setData({ip:res.data.ip});
}
});
}
});