vuejs2 - 使用 Vue2Leaflet 时如何处理点击?
问题描述
我正在使用带有 vuejs2 的 Vue2Leaflet(https://github.com/KoRiGaN/Vue2Leaflet),我已经渲染了地图,并且我想在单击地图时添加一个函数来处理,因为我阅读了文档https://korigan .github.io/Vue2Leaflet/#/但仍然不知道该怎么做。
任何意见,将不胜感激。
解决方案
下面的例子演示了如何处理地图点击事件Vue2Leaflet
:
<l-map :zoom="zoom" :center="center" @click="handleMapClick">
<l-tile-layer :url="url" :attribution="attribution"></l-tile-layer>
</l-map>
export default {
name: "LeafletMap",
components: {
"l-map": LMap,
"l-tile-layer": LTileLayer,
"l-marker": LMarker
},
data() {
return {
zoom: 13,
center: L.latLng(47.41322, -1.219482),
url: "http://{s}.tile.osm.org/{z}/{x}/{y}.png",
attribution:
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
};
},
methods: {
handleMapClick(event) {
//...
}
}
};
这是一个演示
推荐阅读
- python - Pydantic 获取字段类型提示
- load-testing - 在 Gatling 中传递多个标题
- flutter - 如何从 rive 应用程序创建 Flare 文件?颤振耀斑动画
- python - 为什么我不能正常使用我的包裹?派皮
- react-native - 是的,使用正则表达式进行模式验证不断给我字段错误
- python - 在 IDLE shell 中使用任何不带参数的函数会使我的计算机崩溃
- javascript - 如何将 JavaScript 对象转换为表格行?
- html - 为什么“相同”的代码在相同大小的相同浏览器中看起来不同,其中一个部署在本地主机上,另一个部署在远程
- reactjs - React - 有条件的如果仍然通过,即使它是错误的
- java - 获取R2DBC失败,此发布者不支持多订阅者