使用vue.extend()
createInfoWindow() {
var _this = this
var MyComponent = Vue.extend({
template: '<div style="width: 500px">' +
'<div class="title">温室</div>' +
'<div class="sub-title">实时数据</div>' +
'<table class="data-table">' +
'<tr><th>空气温度</th><th>空气温度</th>/tr>' +
'<tr><td>{{latestInfo.airtemp}}</td>'+
'<td>{{latestInfo.airhumi}}</td></tr>'+
'</table>' +
'<button class="his-data-btn" id="his-data-btn" v-on:click="showHisData()">查看历史数据</button>' +
'</div>',
data() {
return {
latestInfo: {
airtemp: null,
airhumi: null
},
}
},
methods: {
// 控制折线图的显示, 此处的showHisData() 即为button的click方法
showHisData:function() {
isShow在外部的data中定义,此处可拿过来直接使用,不用在Vue.extend中定义
_this.isShow = !this.isShow
}
},
})
// 将新创建的子组件进行挂载
var component= new MyComponent().$mount();
// 将窗体内容添加到infoWindow中
this.infoWindow = new AMap.InfoWindow({
content : component.$el,
size: 500
});
// 打开窗体
this.infoWindow.open(this.map, [116.397428, 39.90923]);
}
高德地图的infowindow使用click方法
最新推荐文章于 2024-06-20 15:40:20 发布