how to use vue-router params

后端 未结 4 1752
被撕碎了的回忆
被撕碎了的回忆 2021-02-12 08:06

I\'m new to vue now working with its router. I want to navigate to another page and I use the following code:

this.$router.push({path: \'/newLocation\', params:          


        
4条回答
  •  滥情空心
    2021-02-12 09:06

    The easiest way I've found is to use named routes along with the params options. Let's say you have a router file that looks like this:

    And you want to reach the "movie" page with some ID. You can use Vue's router link component (or Nuxt's link component) to reach it like this:

    Vue:

    {{ item.title }}
    

    Nuxt:

    {{ item.title }}
    

    Note that the name parameter must match the "name" attribute of the desired route in the router file. And likewise, the parameter name must match.

    Nuxt creates the route file for you automatically when you create a new page. To see what name Nuxt gives its routes, go to the .Nuxt folder in your project and look for a "router.js" file

提交回复
热议问题