使用 vue2-leaflet 我正在尝试创建一个自定义组件,但我找不到与传单 JS 教程中相同的实现onAdd
和方法。onRemove
<template>
<div>Some text displayed on the map.</div>
</template>
<script lang="ts">
import { Component, Mixins } from 'vue-property-decorator';
import { Map } from 'leaflet';
import { LControl } from 'vue2-leaflet';
@Component
export default class MyControl extends Mixins(LControl) {
onAdd(map: Map) {
console.log('Never called');
}
onRemove(map: Map) {
console.log('Never called');
}
}
</script>
似乎L.Control
传单中的真实内容已存储在其中,this.mapObject
因此我找到了以下解决方法:
export default class MyControl extends Mixins(LControl) {
map: Map | null = null;
mounted() {
this.map = ((this.mapObject as any)._map as Map);
// Do stuff with the map.
}
}
有一个更好的方法吗?