将 VueJS 组件渲染到 Google Map Infowindow 中

Sag*_*Kho 5 javascript google-maps vue.js vuejs2

我正在尝试渲染一个 vue js 组件,它很简单 -

var infowindow_content = "<google-map-infowindow ";
infowindow_content += "content='Hello World'";
infowindow_content += "></google-map-infowindow>";
Run Code Online (Sandbox Code Playgroud)

通过将其传递到标记的信息窗口

this.current_infowindow = new google.maps.InfoWindow({
    content: infowindow_content,
});
this.current_infowindow.open(context.mapObject, marker);
Run Code Online (Sandbox Code Playgroud)

而 vueJS 组件是 -

<template>
    <div>
        {{content}}
    </div>
</template>

<script>
module.exports = {
    name: 'google-map-infowindow',
    props: [ 
        'content',
    ],
}
</script>
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用并且窗口是空白的。

Sag*_*Kho 9

在今天重新审视这个之后,我能够通过以编程方式创建 vue 组件的实例并在简单地将其呈现的 HTML 模板作为信息窗口的内容传递之前安装它来做到这一点。

信息窗口.vue

<template>
    <div>
        {{content}}
    </div>
</template>

<script>
module.exports = {
    name: 'infowindow',
    props: [ 
        'content',
    ],
}
</script>
Run Code Online (Sandbox Code Playgroud)

在打开信息窗口之前需要创建的代码部分:

...
import InfoWindowComponent from './InfoWindow.vue';
...

var InfoWindow = Vue.extend(InfoWindowComponent);
var instance = new InfoWindow({
    propsData: {
        content: "This displays as info-window content!"
    }
});

instance.$mount();

var new_infowindow = new google.maps.InfoWindow({
    content: instance.$el,
});

new_infowindow.open(<map object>, <marker>);
Run Code Online (Sandbox Code Playgroud)

注意:我还没有为此尝试过观察者和事件驱动的调用。