我正在使用vue2-google-maps npm包将Google JS组件集成到Laravel应用程序视图中。
根据npm一揽子文件,我将使用以下方法从npm包中加载vue组件:
import * as VueGoogleMaps from 'vue2-google-maps';
Vue.use(VueGoogleMaps, {
load: {
key: 'mapkey',
libraries: 'places'
}
});然后,我将使用刀片视图中的组件和文档中的示例代码:
<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>但是,我收到以下错误:
未知自定义元素:-正确注册组件吗?对于递归组件,请确保提供"name“选项。
经过一些研究之后,我遇到了使用不同组件名称的这个职位,所以我尝试使用替代组件名称gmap-map &,但这导致了同样的错误。
<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>然后,我尝试直接导入Map和Marker组件,而不是递归地导入所有组件。但是,这会产生相同的错误:
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);我做错了什么?
发布于 2019-06-20 03:40:02
插件中的组件仅当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
});https://stackoverflow.com/questions/56615125
复制相似问题