相关疑难解决方法(0)

将 VueJS 组件渲染到 Google Map Infowindow 中

我正在尝试渲染一个 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)

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

javascript google-maps vue.js vuejs2

5
推荐指数
1
解决办法
2713
查看次数

将 Vue 3 组件渲染为 HTML 字符串

我正在开发一个 vue.js 项目(版本 3)。我遇到了这样一种情况,我想将组件的渲染 HTML 视图用于当前组件的方法。

我在 Vue 项目中创建了以下 SVG 组件。

CircleWithTextSvg.vue

<template>
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd" width="20" height="20">
        <g id="UrTavla">
            <circle cx="10" cy="10" r="10" stroke="gray" stroke-width="1" :fill="fill" />
            <text x="50%" y="50%" text-anchor="middle" stroke="black" stroke-width="1px" dy=".3em">{{text}}</text>
        </g>
    </svg>
</template>

<script>
    export default {
        props: {
            text: { 
                type: String, 
                default: "1"
            },
            fill: { 
                type: String, 
                default: "white"
            }
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

该组件基本上呈现一个内部有文本的圆圈。如果我在主组件的模板部分中使用此组件,如下所示,那么它可以正常工作(显然)

主组件.vue

<template>
    <circle-with-text-svg />
</template>
Run Code Online (Sandbox Code Playgroud)

但我想将此 SVG 组件渲染输出作为选项发送给第三方。

真实用例:-实际上,我创建了这个单独的组件以在我的传单地图上显示为标记。现在的问题是我想在 MainComponent 的方法中使用这个 …

javascript svg leaflet vue.js vuejs3

5
推荐指数
1
解决办法
9730
查看次数

标签 统计

javascript ×2

vue.js ×2

google-maps ×1

leaflet ×1

svg ×1

vuejs2 ×1

vuejs3 ×1