javascript - 传单反应中的 openPopup 出错
问题描述
我在反应时面临传单的问题。我希望当我点击卡片时,我会在我点击的地方弹出,我写了这段代码。它通常在 javascript 中工作,但在 React 中引发错误
this.map.on('click', async function (e) {
var coord = e.latlng;
var lat = coord.lat;
var lng = coord.lng;
var popup = L.popup({minWidth: 30, maxHeight: 300})
.setLatLng([50.51754, 136.94726])
.setContent(`test`)
.openOn(this.map);
});
单击卡片时出现此错误
Unhandled Rejection (TypeError): Cannot read property 'openPopup' of undefined
104 | // @method openOn(map: Map): this
105 | // Adds the popup to the map and closes the previous one. The same as `map.openPopup(popup)`.
106 | openOn: function (map) {
> 107 | map.openPopup(this);
| ^ 108 | return this;
109 | },
110 |
谢谢!
解决方案
推荐阅读
- javascript - 可以播放 MP3 并显示背景图像的 JavaScript 播放器?
- ruby-on-rails - 来自 chrome 检查器的网络技术。是用rails、node.js等写的页面
- python - 如何避免复制代码以相同的方式处理异常、未定义的变量和某些比较
- python - 从没有 NaN 值的多列中的值创建数组
- javascript - 即使我不从外部链接调用,React-native 链接 getinitialurl() 也有效
- electron - 基于浏览器的客户端的重定向 URI
- ruby-on-rails - 如何从活动模型序列化中的关联模型中提取数据?
- python - 计算“石头、纸、剪刀”的平均值
- asp.net-mvc - IIS / ASP.Net 不断渲染已删除的图像
- php - 使用 PHP Simple HTML DOM Parser 解析所有项目