- 可以扩展提供性能api数据吗?
https://developers.weixin.qq.com/miniprogram/dev/api/open-api/performance/wx.getPerformance.html 小程序每个页面性能数据监控提供“首屏完成渲染时间”(可交互时间), 目前通过该api 只可以获取到“firstRender(首次渲染时间)”
2021-03-19 - 小程序自定义组件中使用map无法通过getCenterLocation获取经纬度
小程序自定义组件中封装使用map无法通过getCenterLocation获取经纬度,但是在Page 注册页面中直接调用就可以,不知道这个是小程序自定义组件问题不? 1. 在page 页面中调用是可以通过 regionchange回调通过getCenterLocation获取到中心节点经纬度。 [代码] data: {[代码] [代码] [代码] markers: [{ iconPath: "https://huotu.oss-cn-shanghai.aliyuncs.com/wxx/add_cart@3x.png", id: 0, latitude: 23.099994, longitude: 113.324520, width: 50, height: 50 }], polyline: [{ points: [{ longitude: 113.3245211, latitude: 23.10229 }, { longitude: 113.324520, latitude: 23.21229 }], color: "#FF0000DD", width: 2, dottedLine: true }], controls: [{ id: 1, iconPath: 'https://huotu.oss-cn-shanghai.aliyuncs.com/wxx/conplete-center@3x.png', position: { left: 0, top: 300 - 50, width: 50, height: 50 }, clickable: true }] [代码][代码] [代码] },[代码] [代码] onShow: [代码][代码]function[代码] [代码]() {[代码] [代码] [代码][代码]this[代码][代码].mapCtx = wx.createMapContext([代码][代码]'myMap'[代码][代码])[代码][代码] [代码][代码]},[代码][代码] [代码][代码]regionchange(e) {[代码][代码] [代码][代码]if[代码][代码](e.type == [代码][代码]'end'[代码][代码]) {[代码][代码] [代码][代码]console.log(e)[代码][代码] [代码][代码]console.log([代码][代码]this[代码][代码].mapCtx)[代码][代码] [代码][代码]this[代码][代码].mapCtx.getCenterLocation({[代码][代码] [代码][代码]success: (res) => {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]},[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码] [代码] [代码][代码]},[代码] 2. 但是经同样额代码放在自定义组件就不可以获取到经纬度 组件代码(map-native): [代码]// pages/components/map-native/index.js[代码][代码]Component({[代码][代码] [代码][代码]/**[代码][代码] [代码][代码]* 组件的属性列表[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]properties: {[代码] [代码] [代码][代码]},[代码] [代码] [代码][代码]/**[代码][代码] [代码][代码]* 组件的初始数据[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]markers: [{[代码][代码] [代码][代码]iconPath: [代码][代码]"https://huotu.oss-cn-shanghai.aliyuncs.com/wxx/add_cart@3x.png"[代码][代码],[代码][代码] [代码][代码]id: 0,[代码][代码] [代码][代码]latitude: 23.099994,[代码][代码] [代码][代码]longitude: 113.324520,[代码][代码] [代码][代码]width: 50,[代码][代码] [代码][代码]height: 50[代码][代码] [代码][代码]}],[代码][代码] [代码][代码]polyline: [{[代码][代码] [代码][代码]points: [{[代码][代码] [代码][代码]longitude: 113.3245211,[代码][代码] [代码][代码]latitude: 23.10229[代码][代码] [代码][代码]}, {[代码][代码] [代码][代码]longitude: 113.324520,[代码][代码] [代码][代码]latitude: 23.21229[代码][代码] [代码][代码]}],[代码][代码] [代码][代码]color: [代码][代码]"#FF0000DD"[代码][代码],[代码][代码] [代码][代码]width: 2,[代码][代码] [代码][代码]dottedLine: [代码][代码]true[代码][代码] [代码][代码]}],[代码][代码] [代码][代码]controls: [{[代码][代码] [代码][代码]id: 1,[代码][代码] [代码][代码]iconPath: [代码][代码]'https://huotu.oss-cn-shanghai.aliyuncs.com/wxx/conplete-center@3x.png'[代码][代码],[代码][代码] [代码][代码]position: {[代码][代码] [代码][代码]left: 0,[代码][代码] [代码][代码]top: 300 - 50,[代码][代码] [代码][代码]width: 50,[代码][代码] [代码][代码]height: 50[代码][代码] [代码][代码]},[代码][代码] [代码][代码]clickable: [代码][代码]true[代码][代码] [代码][代码]}],[代码][代码] [代码][代码]mapCtx: [代码][代码]null[代码][代码],[代码][代码] [代码][代码]},[代码][代码] [代码][代码]ready() {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]mapCtx: wx.createMapContext([代码][代码]'myMap'[代码][代码])[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]/**[代码][代码] [代码][代码]* 组件的方法列表[代码][代码] [代码][代码]*/[代码][代码] [代码][代码]methods: {[代码][代码] [代码][代码]regionchange(e) {[代码][代码] [代码][代码]if[代码] [代码](e.type == [代码][代码]'end'[代码][代码]) {[代码][代码] [代码][代码]console.log(e)[代码][代码] [代码][代码]console.log([代码][代码]this[代码][代码].data.mapCtx)[代码][代码] [代码][代码]console.log([代码][代码]this[代码][代码].data.mapCtx.getCenterLocation)[代码][代码] [代码][代码]this[代码][代码].data.mapCtx.getCenterLocation({[代码][代码] [代码][代码]success: (res) => {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: (res) => {[代码][代码] [代码][代码]console.log(res)[代码][代码] [代码][代码]},[代码][代码] [代码][代码]complete: (complete) => {[代码][代码] [代码][代码]console.log(2222)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码] [代码] [代码][代码]},[代码][代码] [代码][代码]}[代码][代码]})[代码]模板: [代码]<[代码][代码]map[代码] [代码]id[代码][代码]=[代码][代码]"myMap"[代码] [代码]longitude[代码][代码]=[代码][代码]"113.324520"[代码] [代码]latitude[代码][代码]=[代码][代码]"23.099994"[代码] [代码]scale[代码][代码]=[代码][代码]"14"[代码] [代码]controls[代码][代码]=[代码][代码]"{{controls}}"[代码] [代码]bindcontroltap[代码][代码]=[代码][代码]"controltap"[代码] [代码]markers[代码][代码]=[代码][代码]"{{markers}}"[代码] [代码]bindmarkertap[代码][代码]=[代码][代码]"markertap"[代码] [代码]polyline[代码][代码]=[代码][代码]"{{polyline}}"[代码] [代码]bindregionchange[代码][代码]=[代码][代码]"regionchange"[代码] [代码]show-location [代码][代码]style[代码][代码]=[代码][代码]"width: 400px; height: 300px;"[代码][代码]></[代码][代码]map[代码][代码]>[代码] 页面调用: <map-native></map-native>
2018-05-12