pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <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="wkgek2m" 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="agccicq" 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="2yuw2wa" 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>

                            主站蜘蛛池模板: 【黄页88网】-B2B电子商务平台,b2b平台免费发布信息网 | 广州各区危化证办理_危险化学品经营许可证代办| ET3000双钳形接地电阻测试仪_ZSR10A直流_SXJS-IV智能_SX-9000全自动油介质损耗测试仪-上海康登 | 粉末包装机-给袋式包装机-全自动包装机-颗粒-液体-食品-酱腌菜包装机生产线【润立机械】 | 科昊仪器超纯水机系统-可成气相液氮罐-美菱超低温冰箱-西安昊兴生物科技有限公司 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 加气混凝土砌块设备,轻质砖设备,蒸养砖设备,新型墙体设备-河南省杜甫机械制造有限公司 | 高防护蠕动泵-多通道灌装系统-高防护蠕动泵-www.bjhuiyufluid.com慧宇伟业(北京)流体设备有限公司 | EFM 022静电场测试仪-套帽式风量计-静电平板监测器-上海民仪电子有限公司 | 轴流风机-鼓风机-离心风机-散热风扇-罩极电机,生产厂家-首肯电子 | YT保温材料_YT无机保温砂浆_外墙保温材料_南阳银通节能建材高新技术开发有限公司 | 小型铜米机-干式铜米机-杂线全自动铜米机-河南鑫世昌机械制造有限公司 | 河南档案架,档案密集架,手动密集架,河南密集架批发/报价 | 气体检测仪-氢气检测仪-可燃气体传感器-恶臭电子鼻-深国安电子 | 电动不锈钢套筒阀-球面偏置气动钟阀-三通换向阀止回阀-永嘉鸿宇阀门有限公司 | 自动化生产线-自动化装配线-直流电机自动化生产线-东莞市慧百自动化有限公司 | 耐力板-PC阳光板-PC板-PC耐力板 - 嘉兴赢创实业有限公司 | 湿地保护| 专业深孔加工_东莞深孔钻加工_东莞深孔钻_东莞深孔加工_模具深孔钻加工厂-东莞市超耀实业有限公司 | 活性炭厂家-蜂窝活性炭-粉状/柱状/果壳/椰壳活性炭-大千净化-活性炭 | 扬尘监测_扬尘监测系统_带证扬尘监测设备 - 郑州港迪科技有限公司 | 成人纸尿裤,成人尿不湿,成人护理垫-山东康舜日用品有限公司 | 滚筒烘干机_转筒烘干机_滚筒干燥机_转筒干燥机_回转烘干机_回转干燥机-设备生产厂家 | 科箭WMS仓库管理软件-TMS物流管理系统-科箭SaaS云服务 | 中矗模型-深圳中矗模型设计有限公司| 郑州水质检测中心_井水检测_河南废气检测_河南中环嘉创检测 | 一体化预制泵站-一体化提升泵站-一体化泵站厂家-山东康威环保 | 龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司_龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司 | 导电银胶_LED封装导电银胶_半导体封装导电胶厂家-上海腾烁 | 烟台金蝶财务软件,烟台网站建设,烟台网络推广 | 密封圈_泛塞封_格莱圈-[东莞市国昊密封圈科技有限公司]专注密封圈定制生产厂家 | 沈阳缠绕包装机厂家直销-沈阳海鹞托盘缠绕包装机价格 | 武汉高低温试验机-现货恒温恒湿试验箱-高低温湿热交变箱价格-湖北高天试验设备 | 杭州代理记账费用-公司注销需要多久-公司变更监事_杭州福道财务管理咨询有限公司 | 东莞螺丝|东莞螺丝厂|东莞不锈钢螺丝|东莞组合螺丝|东莞精密螺丝厂家-东莞利浩五金专业紧固件厂家 | 蒸汽热收缩机_蒸汽发生器_塑封机_包膜机_封切收缩机_热收缩包装机_真空机_全自动打包机_捆扎机_封箱机-东莞市中堡智能科技有限公司 | 真空干燥烘箱_鼓风干燥箱 _高低温恒温恒湿试验箱_光照二氧化碳恒温培养箱-上海航佩仪器 | 小型手持气象站-空气负氧离子监测站-多要素微气象传感器-山东天合环境科技有限公司 | 杭州货架订做_组合货架公司_货位式货架_贯通式_重型仓储_工厂货架_货架销售厂家_杭州永诚货架有限公司 | 培训一点通 - 合肥驾校 - 合肥新亚驾校 - 合肥八一驾校 | 武汉森源蓝天环境科技工程有限公司-为环境污染治理提供协同解决方案 |