微信小程序获得服务器ip

错误:
有时候在小程序前端能取到图片的地址,但是不显示
解决方法:
可能是数据库中只存了图片的服务器地址,但是地址不全
例:

1
/pages/member/info/index

但如果要显示到页面上需要加ip。即:

1
192.168.100.103/pages/member/info/index

即在前端:

1
<image src='{{attachment}}{{item.static_image}}'></image>

后台js:

1
2
3
4
5
6
7
8
var t = getApp(),
a = t.requirejs("core"),
e = (t.requirejs("icons"), t.requirejs("wxParse/wxParse"));
Page({
data: {
attachment: t.globalData.attachment
}
})

在微信小程序中定义全局变量:

1
2
3
4
5
6
7
8
9
globalData: {
rencent_order_time_before: 30,//最近订单中往前显示订单的时间
custom_service_phonenumber: "023-5519827",//客服电话
appid: "wx68c04a444055058c",
api: "http://192.168.100.12:8080/app/ewei_shopv2_api.php?i=1",
approot: "http://192.168.100.12:8080/addons/ewei_shopv2/",
attachment: "http://192.168.100.12:8080/attachment/",
userInfo: null
}