this转换为that问题
1.场景1
const that = thisif (dd.env.platform !== "notInDingTalk") {dd.ready(function () {dd.runtime.permission.requestAuthCode({ onSuccess: function (info) {that.$router.push({ name: 'orderingAdd', params: { type_data: type_data} });}});});}
在使用异步加载时,使用this转换为that,可以在异步空间中使用页面其他方法。
2.场景2
marker.addEventListener("click", function () {var infoWindow = new BMap.InfoWindow("World", opts); // 创建信息窗口对象that.map.openInfoWindow(infoWindow, that.map.getCenter()); // 打开信息窗口that.openInfo("2")});
动态创建生产点击方法时,可以使用this转换为that,可以在空间中使用页面其他方法。