将 Google Maps VueJS 组件 (vue2-google-maps) 集成到 Laravel blade 视图中

Integrating Google Maps VueJS Components (vue2-google-maps) into a Laravel blade view

我正在将 Google Maps Vue JS 组件集成到 Laravel 应用程序视图中,使用 vue2-google-maps npm 包.

根据 npm package documentation 我正在使用 npm 包加载 vue 组件:

import * as VueGoogleMaps from 'vue2-google-maps';

Vue.use(VueGoogleMaps, {
  load: {
    key: 'mapkey',
    libraries: 'places'
  }
});

然后我将 blade 视图中的组件与文档中的示例代码一起使用:

    <GmapMap
      :center="{lat:10, lng:10}"
      :zoom="7"
      map-type-id="terrain"
      style="width: 100%; height: 500px" 
      id="googleMap"
    >
        <GmapMarker
            :key="index"
            v-for="(m, index) in mapPoints"
            :position="m.position"
            :clickable="true"
            :draggable="true"
            @click="center=m.position"
        >
        </GmapMarker>
    </GmapMap>

但是,我收到以下错误:

Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.


经过一番研究,我发现 this post 使用了不同的组件名称,因此我尝试使用替代组件名称 gmap-map & gmap-marker,但这导致了同样的错误。

<gmap-map
  :center="center"
  :zoom="12"
  style="width:100%;  height: 400px;"
>
  <gmap-marker
    :key="index"
    v-for="(m, index) in markers"
    :position="m.position"
    @click="center=m.position"
  ></gmap-marker>
</gmap-map>

然后我尝试直接导入地图和标记组件,而不是递归地导入所有组件。但是,这会产生相同的错误:

import GmapMap from 'vue2-google-maps/src/components/map';
import GmapMarker from 'vue2-google-maps/src/components/marker';

Vue.component('GmapMap', GmapMap);
Vue.component('GmapMarker', GmapMarker);

我做错了什么?

插件中的组件仅在 installComponents 选项设置为 true 时安装。

https://github.com/xkjyeah/vue-google-maps/blob/v0.10.5/src/main.js#L69

import * as VueGoogleMaps from 'vue2-google-maps';

Vue.use(VueGoogleMaps, {
  load: {
    key: 'mapkey',
    libraries: 'places'
  },
  installComponents: true
});