当前位置: 代码迷 >> 综合 >> vue开发过程this转换为that问题
  详细解决方案

vue开发过程this转换为that问题

热度:8   发布时间:2024-01-30 22:40:24.0

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,可以在空间中使用页面其他方法。

  相关解决方案