[解读小程序]手机归属地查询Demo(一)
分析的程序来源:
http://blog.csdn.net/y1258429182/article/details/52666290
下载链接:http://pan.baidu.com/s/1o8bElya 密码:b621
解压密码: yangzheshare
app.js (小程序的入口)
这里声明了getDataFromServer()的方法. 使用的是微信提供的API.
wx.request(object)发起网络请求. 文档-发起请求
getDataFromServer(phoneNum,callback) {
wx.request( {
url: 'http://apicloud.mob.com/v1/mobile/address/query?key=17113fceca309&phone='+phoneNum,
data: {
x: '',
y: ''
},
header: {
'Content-Type': 'application/json'
},
success: function( res ) {
console.log( "成功"+res.data )
callback(res.data.result.city)
}
, fail: function( res ) {
console.log( "失败"+res.data )
}
, complete: function( res ) {
console.log( "完成"+res.data )
}
})
}
app.json (配置信息)
pages
pages数组记录了应用中所有的页面. 第一项为启动页面.
"pages": [
"pages/splash/splash",
"pages/login/login",
"pages/index/index",
"pages/logs/logs",
"pages/test/test",
"pages/newDetail/newDetail"
]
tabBar
tabBar用来配置底部Tab栏. list数组的每一个元素就是每一个Tab项. 文档-配置
"tabBar": {
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "pages/img/tab_icon.png",
"selectedIconPath": "pages/img/tab_select_icon.png"
},
{
"pagePath": "pages/test/test",
"text": "测试",
"iconPath": "pages/img/tab_icon.png",
"selectedIconPath": "pages/img/tab_select_icon.png"
},
{
"pagePath": "pages/logs/logs",
"text": "日志",
"iconPath": "pages/img/tab_icon.png",
"selectedIconPath": "pages/img/tab_select_icon.png"
}
]
}
window
window对象用来设置状态栏,导航栏,标题,背景色等 (常见的是在每个Page页面重写navigationBarTitleText来设置每个页面的标题文字内容)
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
}
还要一个debug的布尔值,用来控制是否打印调试信息的.
对于学习这样的新的东西, 文档还是要多看很多遍的.
文档地址
to be continued…