javascript - 在我的传单扩展中访问 VueJS “this”
问题描述
我正在我的 Vuejs 应用程序中使用 Leaflet,并创建了 L.Control 的扩展,如果我可以使用 Vuex 管理它的一部分,它可能会受益匪浅。我只是不完全确定如何在方法中正确获取this
我的 Vue 应用程序L.Control.extend
。
现在,我正在定义let that = this;
和使用that
任何我想处理 Vuejs 数据的时间,但这是最好的方法吗?这有限制吗?
这是我当前如何实现此功能的精简示例。
mounted() {
let that = this;
L.Control.ZoomUserLocation = L.Control.extend({
_zoomUserLocation: function() {
navigator.geolocation.getCurrentPosition(
function success(position) {
let lat = position.coords.latitude;
let lng = position.coords.longitude;
if (that.userLocationMarker !== null) {
that.userLocationMarker.remove();
}
that.userLocationMarker = L.marker([lat, lng]).addTo(map);
},
function error(error_message) {...}
);
}
else {
map.setView([that.center.lat, that.center.lng], that.zoom);
}
},
})
}
解决方案
推荐阅读
- css - 在复选框内标记
- django - 如何在视图中同时保存多个模型形式(1:1)(Django)
- android - 无法解析符号 FacebookSdk
- c# - 事件 'Command.CanExecuteChanged' 只能出现在 += 或 -= 的左侧
- javascript - 不使用deferred实现异步操作
- c# - 从 Asp.Net MVC 中的 sAuth URL 获取 Json 响应
- postgresql - 角色与 PostgreSQL 中的 pg_terminate_backend 和/或 pg_cancel_backend 管理函数之间的关系
- vba - Big Excel:Makro 不运行,Excel 不响应
- angular - 如何将客户选择的评级传递给角度组件
- java - 使用 @PathVariable SpringBoot 将信息 /current ID/ 传递给子控制器