gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 22:37:35 25 4
gpt4 key购买 nike

我正在尝试渲染一个简单的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com