map 생성이 되면 this.map에 담아 주나요?
아래 코드도 함께 참고해주세요.
export default {
name: 'app',
data() {
return {
map: null
};
},
mounted() {
this.initMap();
},
methods: {
initMap() {
let container = document.getElementById('map');
let options = {
center: new kakao.maps.LatLng(37.566826, 126.9786567),
level: 3
};
let map = new kakao.maps.Map(container, options);
this.map = map;
this.geocoder = new kakao.maps.services.Geocoder();
},
searchSubmit() {
this.geocoder.addressSearch('해남군 송지면', (result, status) => {
if (status === kakao.maps.services.Status.OK) {
let bounds = new kakao.maps.LatLngBounds();
for (let i = 0; i < result.length; i++) {
let data = result[i];
bounds.extend(new kakao.maps.LatLng(data.y, data.x));
}
this.map.setBounds(bounds);
}
});
}
}
};