从子路由导航到父路由,不会重新挂载父路由

时间:2021-05-26 13:37:25

标签: vue.js vue-router vuejs3 vue-composition-api

每当我路由到 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

它在加载时看起来如何 enter image description here

按下新线索并单击返回 Adventure 后的外观,从子级导航返回时不会加载地图。

enter image description here

可能有什么问题?

我如何加载地图

 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);

    })

0 个答案:

没有答案