How do vue routes pass parameters? How to get the parameters on the second page

routing main.js

{
    name:"hotel",
    path:"/hotel/:id",
    component:Hotel
}
  1. list.vue page < router-link: to= "{path:"/hotel/"+item.id}" > is like this. I want to pass item.id to the hotel.vue page. Click url to jump to http://localhost:8080/-sharp/hotel/1

  2. I am in the hotel.vue page

  mounted(){
      console.log(this.$vm.$route.params) //
      //,
//$route is not defined
  }

can"t get the parameter? How to do

in addition, if you change it to the following < router-link: to= "{path:"/hotel",params: {id:item.id}}" > , http://localhost:8080/-sharp/hotel doesn"t know why it doesn"t even have a suffix

.
Apr.11,2021

< router-link: to= "{path:'/hotel',params: {id:item.id}}" >


< router-link: to=' {name: "hotel", params: {id:item.id}}'>
try


print this.route will report an error $route is not defined , do I also need to import vue-router in hotel.vue? I actually quote


this.$route.params


the < router-link: to=' {name: "hotel", params: {id:item.id}}'> that I got with this seems to be because params needs name to get

.
Menu