每当我路由到 NewClue
然后返回 Adventure
时,它都不会触发 onMounted 函数,为什么会发生这种情况?但是当我在冒险中使用 f5 刷新页面时,它会加载。
Adventure.vue
.map-col(ref="mapCol" v-if="route.name == 'Adventure'")
| Route name: {{route.name}} //shows adventure, but it doesn't load the map
.map-col.px-2(v-else)
router-view
也试过了
router-view(:key="route.fullPath")
{
path: "/adventures/id",
name: "Adventure",
component: Adventure,
children: [
{
path: "points/id/clues/new",
name: "NewClue",
component: NewClue
}
]
}
]
NewClue.vue
router-link(:to="{name: 'Adventure'}")
| Back
按下新线索并单击返回 Adventure
后的外观,从子级导航返回时不会加载地图。
可能有什么问题?
我如何加载地图
onMounted(async () => {
await loader.load()
map.value = new google.maps.Map(mapCol.value, {
center: { lat: currPos.value.lat, lng: currPos.value.lng },
zoom: 15,
mapTypeId: "roadmap",
});
await useMapSearch(map.value, mapSearch.value);
})