0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

App.vueのonMountedでrouteのパラメタがうまく使えないぞ?な時

Posted at

🤷 mountedでうまく値がとれないよォ〜

App.vue
const route = useRoute()
onMounted(() => {
  console.log(route.path) // => /
  console.log(route.params) // => {}
  console.log(route.query) // => {}
})

👮 isReady()を使ってください

App.vue
const router = useRouter();
const route = useRoute()
onMounted(async () => {
  await router.isReady()
  console.log(route.path)
  console.log(route.params)
  console.log(route.query)
})

routerが準備できていれば使用できるので、router-view内のコンポーネントではonMountedでも値が取れます

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?