我正在開發一個 Ionic 應用程式,該應用程式的頁面之一是帶有傳單地圖部分的地點詳細資訊。
第一次在地點詳細資訊頁面上輸入時,地圖作業正常,但是當回傳并在另一個地點詳細資訊頁面上輸入時,會出現錯誤:
錯誤:“地圖容器已初始化。”
我添加了部分代碼來關閉和洗掉地圖,但從未進入,因為始終未定義,但是當我嘗試創建它時,它告訴我它已初始化。
組件.st:
ionViewWillEnter() {
if (this.placeMapLeaflet) {
this.placeMapLeaflet.off();
this.placeMapLeaflet.remove();
}
this.placeMapLeaflet = L.map("place_map_leaflet").setView([position.lat, position.lng], this.zoom);
}
問題是第二次總是未定義但已初始化。
有人可以幫我嗎?
uj5u.com熱心網友回復:
用生命周期解決:
...
ionViewDidEnter() {
this.placeMapLeaflet = L.map("place_map_leaflet").setView([position.lat, position.lng], this.zoom);
}
ionViewDidLeave() {
this.placeMapLeaflet.off();
this.placeMapLeaflet.remove();
}
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/366563.html
