1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 如何在高德地图windowInfo弹窗中使用VUE组件

如何在高德地图windowInfo弹窗中使用VUE组件

时间:2019-07-25 07:56:40

相关推荐

如何在高德地图windowInfo弹窗中使用VUE组件

项目中,使用高德地图的API,有个需求是在点击marker标记的时候,需要弹出windowInfo弹窗,然后弹窗中还有操作等

分析:

windowInfo中的content接口一组html字符串,但是如果有操作的话,还要动态的操作dom,写起来费劲不说,还很容易出bug

但是在vue.js 的API中有个el选项,可以获取到vue的dom等

有了这个属性,就可以使用vue组件加入到windowInfo中,然后弹窗方法和内容都写在弹窗组件中就可以了,方法如下

import BaseDeviceDetail from "@/components/baseDeviceDetail/BaseDeviceDetail";<script>components: {'base-device': BaseDeviceDetail},methods: {createInfoDom(infoWindow, item){let Content = Vue.extend({template: `<base-device :data="item"></base-device>`,name: 'DeiceDetail',data(){return {item: item}}});let component = new Content().$mount();infoWindow.setContent(component.$el);infoWindow.open(this.map, [+item.deviceLongitude, +item.deviceLatitude]);}}</script>

这样写完了之后,发现报错,说我没有注册组件

注册组件应该放在VUE的实例中去才可以,如下

import BaseDeviceDetail from "@/components/baseDeviceDetail/BaseDeviceDetail";<script>methods: {createInfoDom(infoWindow, item){let Content = Vue.extend({template: `<base-device :data="item"></base-device>`,name: 'DeiceDetail',components: {'base-device': BaseDeviceDetail},data(){return {item: item}}});let component = new Content().$mount();infoWindow.setContent(component.$el);infoWindow.open(this.map, [+item.deviceLongitude, +item.deviceLatitude]);}}</script>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。