Для того чтобы получить this.$route.params.id в разделе setup нужно подключить vue-router
#rootDir/src/components/Examples/Film.vue
<template>
<div>
<button @click="funt">go</button>
</div>
</template>
<script>
import {useRoute} from 'vue-router'
export default {
setup() {
const route = useRoute()
const funt = () => {
console.log(route.params.id)
}
return {
funt,
}
}
}
</script>
Путь прописан так
#rootDir/src/router/index.js
import { createRouter, createWebHistory } from 'vue-router'
import Film from "@/components/Examples/Film";
const routes = [
{
path: '/film/:id',
name: 'film',
component: Film
},
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
export default router

Добавить комментарий