我在我的MapBox map 上添加了自定义按钮,它们可以正确地购物.然而
代码如下所示:
const currentLocationControl = new CustomControl('current-location-control', 'GPS');
this.map.addControl(currentLocationControl, 'top-left');
document.getElementById('test').addEventListener('click', function (e) {
alert('test');
});
我在vue.js
的mounted
方法中执行这段代码.
CustomControl:
export default class CustomControl {
constructor(className, text) {
this.className = className;
this.text = text;
}
onAdd(map){
this.map = map;
this.container = document.createElement('div');
this.container.id = 'test';
this.container.className = this.className;
this.container.textContent = this.text;
return this.container;
}
onRemove(){
this.container.parentNode.removeChild(this.container);
this.map = undefined;
}
}
当我console.log(document.getElementById('test'));
时,我在控制台(test div)中看到了预期的结果.
那么这里会发生什么?