久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <small id='nCLD5'></small><noframes id='nCLD5'>

  • <legend id='nCLD5'><style id='nCLD5'><dir id='nCLD5'><q id='nCLD5'></q></dir></style></legend>

    <tfoot id='nCLD5'></tfoot>

          <bdo id='nCLD5'></bdo><ul id='nCLD5'></ul>
        <i id='nCLD5'><tr id='nCLD5'><dt id='nCLD5'><q id='nCLD5'><span id='nCLD5'><b id='nCLD5'><form id='nCLD5'><ins id='nCLD5'></ins><ul id='nCLD5'></ul><sub id='nCLD5'></sub></form><legend id='nCLD5'></legend><bdo id='nCLD5'><pre id='nCLD5'><center id='nCLD5'></center></pre></bdo></b><th id='nCLD5'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nCLD5'><tfoot id='nCLD5'></tfoot><dl id='nCLD5'><fieldset id='nCLD5'></fieldset></dl></div>

        Vuejs Leaflet:找不到地圖容器

        Vuejs Leaflet : Map Container Not Found(Vuejs Leaflet:找不到地圖容器)
              <tbody id='HvVuR'></tbody>
              <tfoot id='HvVuR'></tfoot>
                <legend id='HvVuR'><style id='HvVuR'><dir id='HvVuR'><q id='HvVuR'></q></dir></style></legend>
                  <bdo id='HvVuR'></bdo><ul id='HvVuR'></ul>
                  <i id='HvVuR'><tr id='HvVuR'><dt id='HvVuR'><q id='HvVuR'><span id='HvVuR'><b id='HvVuR'><form id='HvVuR'><ins id='HvVuR'></ins><ul id='HvVuR'></ul><sub id='HvVuR'></sub></form><legend id='HvVuR'></legend><bdo id='HvVuR'><pre id='HvVuR'><center id='HvVuR'></center></pre></bdo></b><th id='HvVuR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HvVuR'><tfoot id='HvVuR'></tfoot><dl id='HvVuR'><fieldset id='HvVuR'></fieldset></dl></div>

                • <small id='HvVuR'></small><noframes id='HvVuR'>

                  本文介紹了Vuejs Leaflet:找不到地圖容器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試在 Vue 中使用傳單地圖,但不斷收到錯誤消息:

                  <塊引用>

                  未捕獲的錯誤:未找到地圖容器.

                  這是我的組件的樣子:

                  <template><div id="app" class="container">地圖<div class="col-md-9"><div id="mapid"></div></div></div></模板><樣式范圍>#mapid {高度:800px;}</風格><腳本>從傳單"導入 Lvar mymap = L.map('mapid').setView([51.505, -0.09], 13);L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={}', {attribution: '地圖數據和副本;<a >OpenStreetMap</a>貢獻者,<a >CC-BY-SA</a>,圖像 ? <a mapbox.streets',訪問令牌:''}).addTo(mymap);</腳本>

                  我還在 index.html 頭中添加了 Leaflet CSS 和 JavaScript.

                  解決方案

                  歡迎來到 SO!

                  當您嘗試實例化您的傳單地圖時通過傳遞您的元素 ID (L.map('mapid')),問題是你的 Vue 組件還沒有附加到你的頁面 DOM.因此,當 Leaflet 嘗試查詢后者以找到您的元素時,它找不到它,因此您的錯誤消息.

                  如果你嘗試在 mounted 生命周期鉤子中實例化,同樣的事情:你的 Vue 組件實例被創建并且它的片段 HTML 結構被構建,但仍然沒有附加到頁面 DOM.

                  但是,您可以直接傳遞您的 Element,而不是傳遞您的 Element id.請注意,您仍然需要在 mounted 掛鉤中這樣做,以確保您的組件實例確實具有構建的 HTML 結構.

                  L.map(<HTMLElement> el, <地圖選項> 選項?)

                  <塊引用>

                  在給定 <div> HTML 元素的實例和可選的帶有 Map options 的對象文字的情況下實例化地圖對象.

                  然后要獲取您的元素,只需利用 Vue $refs 實例屬性和 ref 特殊屬性,如中所述Vue 指南 > 訪問子級組件實例和子元素:

                  <塊引用>

                  [...] 有時您可能仍需要在 JavaScript 中直接訪問子組件.為此,您可以使用 ref 屬性為子組件分配一個引用 ID.

                  因此,在您的情況下,您的模板中有:

                  <div id="mapid" ref="mapElement"></div>

                  在你的組件腳本中:

                  從'leaflet'導入L導出默認 {掛載(){var mymap = L.map(this.$refs['mapElement']).setView([51.505, -0.09], 13);//等等.},}

                  使用 Vue ref 而不是 HTML id 的額外優勢是您可以擁有多個 Vue 組件實例和它們自己的映射,并且 Vue 會為每個腳本引用適當的元素.

                  而對于 HTML id,如果您有多個具有相同 id 的地圖元素,每次您嘗試實例化地圖時,Leaflet 只會獲得第一個,從而引發地圖已為此容器初始化的錯誤.

                  I am trying to use the leaflet map in Vue, but keep getting the error:

                  Uncaught Error: Map container not found.

                  This is what my component looks like:

                  <template>
                    <div id="app" class="container">
                      Map
                      <div class="col-md-9">
                        <div id="mapid"></div>
                      </div>
                    </div>
                  </template>
                  
                  <style scoped>
                  #mapid { 
                      height: 800px;
                  }
                  </style>
                  
                  <script>
                  import L from 'leaflet'
                  
                  var mymap = L.map('mapid').setView([51.505, -0.09], 13);
                  
                  L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={}', {
                      attribution: 'Map data &copy; <a >OpenStreetMap</a> contributors, <a >CC-BY-SA</a>, Imagery ? <a ,
                      maxZoom: 18,
                      id: 'mapbox.streets',
                      accessToken: ''
                  }).addTo(mymap);
                  </script>
                  

                  I have also added the Leaflet CSS and JavaScript under that in my index.html head.

                  解決方案

                  Welcome to SO!

                  When you try instantiating your Leaflet Map by passing it your Element id (L.map('mapid')), the problem is that your Vue component is not yet attached to your page DOM. Therefore when Leaflet tries to query the latter to find your Element, it cannot find it, hence your error message.

                  Same thing if you try instantiating in the mounted lifecycle hook: your Vue component instance is created and its fragment HTML structure is built, but still not attached to the page DOM.

                  But instead of passing your Element id, you can directly pass your Element. Note that you still need to do so in the mounted hook, to ensure that your component instance does have an HTML structure built.

                  L.map(<HTMLElement> el, <Map options> options?)
                  

                  Instantiates a map object given an instance of a <div> HTML element and optionally an object literal with Map options.

                  Then to get your Element, simply leverage Vue $refs instance property and ref special attribute, as described in Vue Guide > Accessing Child Component Instances & Child Elements:

                  […] sometimes you might still need to directly access a child component in JavaScript. To achieve this you can assign a reference ID to the child component using the ref attribute.

                  Therefore in your case you would have in your template:

                  <div id="mapid" ref="mapElement"></div>
                  

                  And in your component script:

                  import L from 'leaflet'
                  
                  export default {
                    mounted() {
                      var mymap = L.map(this.$refs['mapElement']).setView([51.505, -0.09], 13);
                      // etc.
                    },
                  }
                  

                  The added advantage of using Vue ref over HTML id is that you can have several Vue component instances with their own map, and Vue will reference the appropriate Element to each script.

                  Whereas with HTML id, if you have several map Elements with same id, Leaflet will get only the first one every time you try to instantiate your map, raising the error that the map is already initialized for this container.

                  這篇關于Vuejs Leaflet:找不到地圖容器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Check if a polygon point is inside another in leaflet(檢查一個多邊形點是否在傳單中的另一個內部)
                  Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標記群集圖標顏色,繼承其余默認 CSS 屬性)
                  Trigger click on leaflet marker(觸發點擊傳單標記)
                  How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認加載磁貼顏色?)
                  Add external geojson to leaflet layer(將外部geojson添加到傳單層)
                  Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側邊欄)
                  • <small id='PiVOA'></small><noframes id='PiVOA'>

                      • <bdo id='PiVOA'></bdo><ul id='PiVOA'></ul>
                          <tbody id='PiVOA'></tbody>
                        <tfoot id='PiVOA'></tfoot>
                      • <i id='PiVOA'><tr id='PiVOA'><dt id='PiVOA'><q id='PiVOA'><span id='PiVOA'><b id='PiVOA'><form id='PiVOA'><ins id='PiVOA'></ins><ul id='PiVOA'></ul><sub id='PiVOA'></sub></form><legend id='PiVOA'></legend><bdo id='PiVOA'><pre id='PiVOA'><center id='PiVOA'></center></pre></bdo></b><th id='PiVOA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PiVOA'><tfoot id='PiVOA'></tfoot><dl id='PiVOA'><fieldset id='PiVOA'></fieldset></dl></div>

                      • <legend id='PiVOA'><style id='PiVOA'><dir id='PiVOA'><q id='PiVOA'></q></dir></style></legend>

                            主站蜘蛛池模板: 福利一区二区在线 | 精品国产一区二区三区久久久蜜月 | 久久蜜桃资源一区二区老牛 | 亚洲精品视频二区 | 免费国产成人av | 亚洲三级av | 奇米超碰在线 | 欧美精品一区二区三区在线四季 | 91在线精品视频 | hdfreexxxx中国妞 | 中文字幕在线观看第一页 | 在线一区| 亚洲婷婷一区 | 精品区一区二区 | 国产美女黄色片 | 99re视频在线观看 | 不卡一区二区三区四区 | 日韩一区二区在线播放 | 99色播 | 天堂av中文在线 | 日韩精品av一区二区三区 | 国产在线色 | 国产露脸对白88av | 国产伦一区二区三区久久 | 黄色免费观看网站 | 亚洲视频免费播放 | 天天视频一区二区三区 | 亚洲一区 | 一区日韩| 日韩免费1区二区电影 | 一级毛片免费完整视频 | 欧洲尺码日本国产精品 | 久久久久国产精品午夜一区 | 国产精品一区在线观看 | 国产一区二区在线视频 | 日韩免费 | 国产婷婷| 中文字幕日韩一区 | 久久精品亚洲精品 | 欧美精品欧美精品系列 | 91高清视频 |