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="57h777r" 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="5t7dp77" id='HvVuR'><tfoot id='HvVuR'></tfoot><dl id='HvVuR'><fieldset id='HvVuR'></fieldset></dl></div>

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

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

                  問題描述

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

                  <塊引用>

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

                  這是我的組件的樣子:

                  <template><div id="app" class="container">地圖<div class="col-md-9"><div id="mapid"></div></div></div></模板><樣式范圍>#mapid {高度:800px;}</風(fēng)格><腳本>從傳單"導(dǎo)入 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: '地圖數(shù)據(jù)和副本;<a >OpenStreetMap</a>貢獻(xiàn)者,<a >CC-BY-SA</a>,圖像 ? <a mapbox.streets',訪問令牌:''}).addTo(mymap);</腳本>

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

                  解決方案

                  歡迎來到 SO!

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

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

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

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

                  <塊引用>

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

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

                  <塊引用>

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

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

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

                  在你的組件腳本中:

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

                  使用 Vue ref 而不是 HTML id 的額外優(yōu)勢是您可以擁有多個 Vue 組件實例和它們自己的映射,并且 Vue 會為每個腳本引用適當(dāng)?shù)脑?

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

                  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.

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

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

                  相關(guān)文檔推薦

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

                            主站蜘蛛池模板: YJLV22铝芯铠装电缆-MYPTJ矿用高压橡套电缆-天津市电缆总厂 | 标准光源箱|对色灯箱|色差仪|光泽度仪|涂层测厚仪_HRC大品牌生产厂家 | 太平洋亲子网_健康育儿 品质生活 | 河南正规膏药生产厂家-膏药贴牌-膏药代加工-修康药业集团官网 | 液氮罐_液氮容器_自增压液氮罐-北京君方科仪科技发展有限公司 | 周口风机|周风风机|河南省周口通用风机厂 | 学习虾-免费的学习资料下载平台 雪花制冰机(实验室雪花制冰机)百科 | 法兰螺母 - 不锈钢螺母制造厂家 - 万千紧固件--螺母街 | 仿古建筑设计-仿古建筑施工-仿古建筑公司-汉匠古建筑设计院 | elisa试剂盒价格-酶联免疫试剂盒-猪elisa试剂盒-上海恒远生物科技有限公司 | 交变/复合盐雾试验箱-高低温冲击试验箱_安奈设备产品供应杭州/江苏南京/安徽马鞍山合肥等全国各地 | 苏州同创电子有限公司 - 四探针测试仪源头厂家| 北京签证代办_签证办理_商务签证_旅游签证_寰球签证网 | 传动滚筒_厂家-淄博海恒机械制造厂 | 长沙广告公司|长沙广告制作设计|长沙led灯箱招牌制作找望城湖南锦蓝广告装饰工程有限公司 | 丹佛斯变频器-Danfoss战略代理经销商-上海津信变频器有限公司 | 河南生物显微镜,全自动冰冻切片机-河南荣程联合科技有限公司 | 档案密集架_电动密集架_移动密集架_辽宁档案密集架-盛隆柜业厂家现货批发销售价格公道 | 水厂污泥地磅|污泥处理地磅厂家|地磅无人值守称重系统升级改造|地磅自动称重系统维修-河南成辉电子科技有限公司 | ph计,实验室ph计,台式ph计,实验室酸度计,台式酸度计 | 高低温万能试验机_拉力试验机_拉伸试验机-馥勒仪器科技(上海)有限公司 | 权威废金属|废塑料|废纸|废铜|废钢价格|再生资源回收行情报价中心-中废网 | 缓蚀除垢剂_循环水阻垢剂_反渗透锅炉阻垢剂_有机硫化物-郑州威大水处理材料有限公司 | 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 宽带办理,电信宽带,移动宽带,联通宽带,电信宽带办理,移动宽带办理,联通宽带办理 | 济南办公室装修-厂房装修-商铺装修-工装公司-山东鲁工装饰设计 | 硫化罐-胶管硫化罐-山东鑫泰鑫智能装备有限公司 | 电气控制系统集成商-PLC控制柜变频控制柜-非标自动化定制-电气控制柜成套-NIDEC CT变频器-威肯自动化控制 | 薪动-人力资源公司-灵活用工薪资代发-费用结算-残保金优化-北京秒付科技有限公司 | 山东集装箱活动房|济南集装箱活动房-济南利森集装箱有限公司 | 波纹补偿器_不锈钢波纹补偿器_巩义市润达管道设备制造有限公司 | 回收二手冲床_金丰旧冲床回收_协易冲床回收 - 大鑫机械设备 | EPDM密封胶条-EPDM密封垫片-EPDM生产厂家 | 翰香原枣子坊加盟费多少钱-正宗枣核糕配方培训利润高飘香 | 南京租车,南京汽车租赁,南京包车,南京会议租车-南京七熹租车 | POM塑料_PBT材料「进口」聚甲醛POM杜邦原料、加纤PBT塑料报价格找利隆塑料 | 软文发布-新闻发布推广平台-代写文章-网络广告营销-自助发稿公司媒介星 | 今日热点_实时热点_奇闻异事_趣闻趣事_灵异事件 - 奇闻事件 | 哈希PC1R1A,哈希CA9300,哈希SC4500-上海鑫嵩实业有限公司 | 净化车间_洁净厂房_净化公司_净化厂房_无尘室工程_洁净工程装修|改造|施工-深圳净化公司 | 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 |