我在 Nuxt 上也遇到了同样的问题。
<client-only>
<LMap
ref="map"
@hook:mounted="mapInitialization"
:zoom="1"
:center="[640, 512]"
:options="{ attributionControl: false, zoomControl: false }"
:crs="crs"
>
<LImageOverlay :url="url" :bounds="bounds"></LImageOverlay>
<LMarker :lat-lng="[69.5, 177.5]" :z-index="1"></LMarker>
</LMap>
</client-only>
methods: {
mapInitialization() {
const map = this.$refs.map
console.log('MAP FROM STUFF', map)
map.mapObject.setView()
}
}
Mounted 方法中的 $nextTick 对我来说无法正常工作,因为它需要一些勾选,并且在页面引用初始化时为空。
有点晚了,但以下内容应该适用于最新版本的 nuxt3-leaflet :
<template>
<div style="height:100vh; width:100vw">
<LMap
ref="map"
:zoom="zoom"
:max-zoom="18"
:center="[47.21322, -1.559482]"
@ready="mapInitialized"
>
<LTileLayer
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution="&copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors"
layer-type="base"
name="OpenStreetMap"
/>
</LMap>
</div>
</template>
<script setup>
import { ref } from 'vue'
const zoom = ref(6)
const map = ref(null)
// When the map is ready
const mapInitialized = () => {
console.log('Map is ready')
console.log(map.value.maxZoom)
}
</script>