微信小程序常见的问题
一、小程序自定义头部问题
1.自定义头部见代码:
在app.json中加入
"window": { "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "xxx", "navigationBarTextStyle": "black", "navigationStyle": "custom" }, "tabBar": { "color": "#888888", "selectedColor": "#007AFF", "list": [ { "pagePath": "pages/index/index", "text": "首页", "iconPath": "images/home.png", "selectedIconPath": "images/homeact.png" }, { "pagePath": "pages/calltpolice/calltpolice", "text": "告警", "iconPath": "images/calltpolice.png", "selectedIconPath": "images/calltpoliceact.png" }, { "pagePath": "pages/location/location", "text": "信息", "iconPath": "images/location.png", "selectedIconPath": "images/locationact.png" }, { "pagePath": "pages/mine/mine", "text": "我的", "iconPath": "images/mime.png", "selectedIconPath": "images/mimeact.png" } ] },
2.每个页面采用组件头部或者自写头部都可以
二、小程序审核问题
1.小程序审核一般是1~7天,加急审核一年一次
2.审核注意有密码提交必须写
3.审核有视频必须是企业号,个人号不支持视频
三、小程序新版本发布查看仍是历史版本
1.在app.js中加入以下代码
onLaunch: function () { const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 console.log(res.hasUpdate) }) updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success: function (res) { if (res.confirm) { // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启 updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(function () { // 新版本下载失败 }) }
2.注意提交代码版本号与上次必须不同,即可更新
四、小程序中事件问题触发
1.图片、文字使用bindtap="Click"
<!-- 点击事件 bindtap 会有冒泡事件 catchtap 不会有冒泡事件 -->
bindtap catchtap
<!--长按事件 -->
bindlongtap
<!-- 触摸开始 -->
bindtouchstart
<!-- 触摸结束 -->
bindtouchend
五、小程序登录存储问题
1.在app.js全局中加入
App({ onLaunch: function () { // 展示本地存储能力 if (wx.getStorageSync('userinfo')) { wx.switchTab({ url: 'pages/index/index' }) } else { wx.reLaunch({ url: 'pages/login/login' }) } }, globalData: { userInfo: null } })
六、一个邮箱可以注册几个小程序?个人、个体工商户和企业分别可以注册几个小程序?
1.同一个邮箱只能申请注册1个小程序
2.个人和个体工商户可以注册5个小程序
3.企业资质可以注册50个小程序
温馨提示:目前支持中国内地手机号码、身份证、营业执照、组织机构代码(不包括港澳台),其它国家暂不支持。
七、定位问题
1.定位采用微信定位地图,以真机运行为准
在app.json中加入
"permission": { "scope.userLocation": { "desc": "你的位置信息将用于小程序位置接口的效果展示" } }
2.页面加入
<map class="map" longitude='{{longitude}}' latitude='{{latitude}}' scale='{{scale}}' markers='{{markers}}' show-location />
3.逻辑部分
data: { latitude: "", longitude: "", scale: 14, markers: [] }, onLoad: function (options) { var that = this wx.getLocation({ type: 'wgs84', success: function (res) { console.log("经度", res.longitude) var lon = res.longitude var lat = res.latitude console.log("纬度", res.latitude) that.setData({ longitude: lon, latitude: lat, markers: [{ iconPath: "http://zhll.evennet.cn/appImages/images/locationmarks.png", id: 1, latitude: 34.213931, longitude: 108.8800, width: 30, height: 30 }, { iconPath: "http://zhll.evennet.cn/appImages/images/locationmarks.png", id: 2, latitude: 34.213928, longitude: 108.8801, width: 30, height: 30 }, { iconPath: "http://zhll.evennet.cn/appImages/images/locationmarks.png", id: 3, latitude: 34.213930, longitude: 108.8808, width: 30, height: 30 }, { iconPath: "http://zhll.evennet.cn/appImages/images/locationmarks.png", id: 4, latitude: 34.213926, longitude: 108.8803, width: 30, height: 30 }, { iconPath: "http://zhll.evennet.cn/appImages/images/locationmarks.png", id: 5, latitude: 34.213924, longitude: 108.8807, width: 30, height: 30 } ] }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function (e) { this.mapCtx = wx.createMapContext('map') },
八、小程序视频问题
1.小程序中存在视频必须申请企业号方可,建议线上地址
九、小程序echarts问题
1.在弹窗的echarts样式混乱,显示不正常问题
添加如下代码正常:
const chart = echarts.init(canvas, null, { width: 380, height: 350, devicePixelRatio: dpr // 像素 }); canvas.setChart(chart);
十、小程序图片问题,总结
1.小程序图片大多采用在线地址以减小项目大小
注意:自定义tabBar图片必须使用本地地址