xxxxxxxxxx
const props = defineProps({
id: {
required: true,
type: String
}
})
xxxxxxxxxx
created() {
let uri = window.location.search.substring(1);
let params = new URLSearchParams(uri);
console.log(params.get("var_name"));
},
//Without vue-router
xxxxxxxxxx
//we can configure the routes to receive data via the url
//first configure the route so it can receive data:
const routes=[
.
.
{path : '/page/:id?', name='page', component: Page},
.
.
//inside the Page component we can get the data:
name:'Page',
mounted(){
this.url_data=this.$route.params.id;
},
data(){
return{
url_data: null
};
}
//the data can be then used in the template section of the component
<h2> {{url_data}}</h2>
xxxxxxxxxx
<script>
const routes = [
{
path: '/users/:id',
component: () => import('../views/MovieDetails.vue'),
}
];
const router = createRouter({
history: createWebHistory(),
routes
});
</script>
<template>
<div class="span">MovieDetails: {{ $route.params.id }}</div>
</template>