以下皆为个人理解,详情请查看官方文档微信小程序API
微信小程序是一种简单、快速、体积小、有详细的api的程序,下面记录一下开发小程序前期要准备的东西,方便之后开发复制
首先封装全局的接口请求,详情查看另一篇文章
其次微信小程序版本更换提醒、用户要登录,要有头像等信息,在app.js中全局写入
// app.js
App({
onLaunch() {
let that = this
// 判断小程序是否是最新版
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// console.log('onCheckForUpdate====', res)
if (res.hasUpdate) {
console.log('res.hasUpdate====')
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
// console.log('success====', res)
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
})
})
}
})
}
//获取用户头像等信息
wx.getSetting({
success(res) {
console.log('查看时候授权', res)
// 判断用户时候授权
if (res.authSetting['scope.userInfo']) {
wx.getUserInfo({
lang: "zh_CN",
success: res => {
console.log("获取的身份信息", res)
if (res.userInfo) {
that.globalData.userInfo = res.userInfo
}
}
})
}
}
})
},
// 监听小程序隐藏
onHide() {
// 全局监听小程序切入后台,收起键盘
wx.hideKeyboard()
},
globalData: {
userInfo: null
}
})
之后添加底部导航栏
"tabBar": {
"list": [{
"pagePath": "pages/index/index",
"text": "首页"
}, {
"pagePath": "pages/logs/index",
"text": "日志"
}]
},