vue.js - Vue、Leaflet、访问 ref 对象/函数

标签 vue.js leaflet quasar-framework

我在 vue 项目中有一个正在运行的传单 map 。例如(仅包含相关的 vue 代码)。

<div style="height:70vh; width:100%; position: relative;">
      <l-map ref="map" :zoom="maps_obj.zoom" :center="[maps_obj.latitude, maps_obj.longitude]">
        <l-tile-layer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" layer-type="base"></l-tile-layer>
      </l-map>
</div>

<script>
import 'leaflet/dist/leaflet.css';
import { defineComponent, ref } from 'vue';
import {
  LMap, LMarker, LTileLayer, LIcon,
} from '@vue-leaflet/vue-leaflet';
import { icon } from 'leaflet';

methods: {
    test() {
      this.$nextTick(() => {
        this.$refs.map.mapObject.invalidateSize();
      });
    },
  },
</script>

map 本身运行完美。但为什么我无法像文档所述那样访问传单 api 并运行函数? (https://vue2-leaflet.netlify.app/quickstart/#accessing-leaflet-api)

它只是返回错误:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'invalidateSize')
 

最佳答案

当然,在发布这个问题后,我发现了“隐藏的答案”。mapObject现在被称为leafletObject..

this.$refs.map.leafletObject.invalidateSize();

关于vue.js - Vue、Leaflet、访问 ref 对象/函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76062316/

相关文章:

typescript - Vue 3 Typescript ComputedRef 问题

typescript - 扩展或覆盖 vuex 存储的类型定义

javascript - 传单中的圆形标记标签

r - 在 Shiny 中保存传单 map

vue.js - 在 Electron 模式下为Quasar设置API URL

javascript - 如何使用 vue/quasar 验证确认密码

javascript - Vue中如何修改 `App`组件的数据?

javascript - Vue Element.ui 树,发出重新加载事件

javascript - D3 折线图进入bindPopup

firebase - 使用 Firebase 托管部署 Quasar