@Rufix

Как добавить карту от Leaflet через Vue?

App.vue
<template>
  <div id="app">
    <AppMap/>
  </div>
</template>

<script>
import AppMap from './components/AppMap'

export default {
  name: 'App',
  components: {
    AppMap
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>


Компонент с картой:
<template>
  <div class="AppMap" id="AppMap">
    <h1>{{msg}}</h1>
  </div>
</template>

<script>
const mymap = L.map('AppMap').setView([55.75222, 37.61556], 13);

const attribution = '&copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors';

const tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
const tiles = L.tileLayer (tileUrl, {attribution});
tiles.addTo (mymap)

export default {
  name: 'AppMap',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
#AppMap {
  height: 500px;
  width: 800px;
}
</style>


Консоль выдает ошибку "Map container is not found". Помогите решить проблему
  • Вопрос задан
  • 726 просмотров
Решения вопроса 1
0xD34F
@0xD34F Куратор тега Vue.js
<div ref="map">

mounted() {
  this.map = L.map(this.$refs.map).setView([ 55.75222, 37.61556 ], 13);
  ...
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы