javascript - 将 VueJS 组件渲染到 Google Map Infowindow

标签 javascript google-maps vue.js vuejs2

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

var infowindow_content = "<google-map-infowindow ";
infowindow_content += "content='Hello World'";
infowindow_content += "></google-map-infowindow>";

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

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

而 vueJS 组件是 -

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

<script>
module.exports = {
    name: 'google-map-infowindow',
    props: [ 
        'content',
    ],
}
</script>

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

最佳答案

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

InfoWindow.vue

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

<script>
module.exports = {
    name: 'infowindow',
    props: [ 
        'content',
    ],
}
</script>

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

...
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>);

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

关于javascript - 将 VueJS 组件渲染到 Google Map Infowindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50088994/

相关文章:

javascript - 正则表达式 - 量词和捕获组

javascript - 识别 Json 对象中的循环依赖并删除 2 深度后的所有元素

javascript - Google Maps API v3 地理编码

javascript - vuejs中的Array.prototype.splice和arr.splice有什么区别?

javascript - 我们如何在 Nuxt?Vuejs 项目中仅包含来自 lodash 的必需模块?

javascript - 双击 Angular-JS ajax

php - 单击链接以显示下拉菜单

JavaScript 谷歌地图事件处理程序使用粗箭头函数给出错误 - 'Uncaught SyntaxError: Unexpected token >'

ios - 在没有 Podfile 的情况下在 ios9 和 Swift 2 上集成 Google map

javascript - vuejs 2观察不起作用