【发布时间】:2019-08-05 20:28:31
【问题描述】:
我正在尝试使用带有 Vue.js 的 OpenLayers 在我的地图上添加自定义控件。
我有组件 Explore.vue,它使用 OL 创建我的“地图”(olmap),我通过绑定将它传递给子组件 LeftSideBar2.vue。
当我尝试在地图中添加新控件时,Vue 显示以下错误:
[Vue warn]: Error in mounted hook: "TypeError: this.olmap.addControl is not a function"
有人知道发生了什么吗?
我的文件是:
Explore.vue:
模板:
<explore-left-side-bar2 v-bind:olmap="olmap"/>
脚本:
export default {
name: 'Explore',
data () {
return {
olmap: {}
}
},
methods: {
initComponent: function () {
// eslint-disable-next-line
this.olmap = new Map({
target: 'map',
layers: [
baseLayerGroup
],
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
zoom: 5
})
})
}
},
mounted: function () {
this.initComponent()
},
components: {
ExploreLeftSideBar2
}
}
LeftSidebar2.vue:
脚本:
export default {
name: 'LeftSideBar2',
props: ['olmap'],
data () {
return {
}
},
methods: {
initComponent: function () {
var sidebar = new Sidebar({ element: 'ol-sb-sidebar', position: 'left' })
this.olmap.addControl(sidebar)
}
},
mounted: function () {
this.initComponent()
},
components: {
LeftSideBarLayerTree
}
}
【问题讨论】:
标签: javascript vue.js openlayers