🗒️

【Nuxt.js/Vue.js v2】$route.○○でURLのパスやパラメータを取得する

2021/03/17に公開

<script>内ではthis.$route.〇〇
<template>内では以下の通り(this.不要)

$route.path

localhost:3000/search

/search

$route.name

localhost:3000/search

search

$route.query

localhost:3000/search?q=01

{ "q": "01" }

$route.query.○○

(例)$route.query.q

localhost:3000/search?q=01

01

$route.hash

localhost:3000#content

#content

$route.params

localhost:3000/user/1234

{ "uid": "1234" }

$route.params.○○

(例)$route.params.uid

localhost:3000/user/1234

1234

$route.fullPath

localhost:3000/search?q=01#content

/search?q=01#content

Discussion