I'm trying to render a vue js component which is simply -
var infowindow_content = "<google-map-infowindow ";
infowindow_content += "content='Hello World'";
infowindow_content += "></google-map-infowindow>";
by passing it into the marker's infowindow
this.current_infowindow = new google.maps.InfoWindow({
content: infowindow_content,
});
this.current_infowindow.open(context.mapObject, marker);
And the vueJS component being -
<template>
<div>
{{content}}
</div>
</template>
<script>
module.exports = {
name: 'google-map-infowindow',
props: [
'content',
],
}
</script>
However, this doesn't work and the window is blank.
After revisiting this today I was able to do this by programmatically creating an instance of the vue component and mounting it before simply passing its rendered HTML template as the infowindow's content.
InfoWindow.vue
And in the portion of the code that is required to create before opening the info-window: ... import InfoWindowComponent from './InfoWindow.vue'; ...
Note: I haven't experimented with watchers and event-driven calls for this.
In vue.js template interpolation with the "double moustaches" interprets its contents as plain text, not HTML (thus escaping it). If you want to emit HTML, you need to user the
v-html
directive:For reference, see Raw HTML in the guide and the v-html API docs.
Note that in this way, data bindings are not considered, so I'm not really sure that manipulating raw HTML is the best strategy here.