How to get query parameters in Vue
Query parameters in Vue
The easiest way to get query parameters in Vue is from the URL is using useRoute
from vue-router
.
- Make sure the
vue-router
is installed,yarn add vue-router
ornpm i vue-router
. - Get query parameter inside the script tag.
<script lang="ts" setup>
import { useRoute } from 'vue-router';
const route = useRoute();
// i.e the url parameter look like this: https://example.com?name=Bob
console.log(route.query.name); // Bob
</script>