【问题标题】:vue and google map infowindowvue 和谷歌地图信息窗口
【发布时间】:2018-02-14 11:02:37
【问题描述】:

我正在使用 vue 和谷歌地图,我希望通过更新信息窗口中显示的数据来获得实时体验。我试过以下:

var infoStr =   
'<table class="">'+                                    
   '<tbody>' +
       '<tr>' +
          '<td colspan="2">{{testInfo}}</td>' +
       '</tr>' +                                        
    '</tbody>'+
'</table >';

var infowindow = new google.maps.InfoWindow({
   content: infoStr
});

global.infoWindow = infowindow;
infowindow.open(map, marker);

应用程序显示 {{testInfo}} 就像它是一个字符串并且未绑定。无论如何要在 InfoWindow 中绑定数据,以便我可以将其绑定到 Vue 数据?

【问题讨论】:

    标签: google-maps vue.js vuejs2


    【解决方案1】:

    您的问题是,当您将{{testInfo}} 放入变量infoStr 时,您将其设为静态,因此在创建信息窗口时它的值仅为{{testinfo}}

    作为一种解决方法,我建议您将id="info-win-1" 属性添加到您的信息窗口代码中。

    var infoStr =   
       '<table class="">'+                                    
         '<tbody>' +
         '<tr>' +
           '<td id="info-win-1" colspan="2">{{testInfo}}</td>' +
         '</tr>' +                                        
         '</tbody>'+
       '</table >';
    

    var infowindow = new google.maps.InfoWindow({ 内容:infoStr });

    这样您就可以在您的 vue 应用中使用 document.getElementById("info-win-1").innerHTML = testInfo 动态更改内容。

    【讨论】:

    • 感谢您的回复。元素什么时候会出现在 DOM 中?我尝试了以下操作: infowindow.open(map, marker); document.getElementById("info-win").innerHTML = 'ikke sat';但此时该元素不可用(我得到一个空引用 og getElement)?
    • 看看这个渲染Fucntions & JSX
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多