多参数路由

知识点

  • 路由属性props

实战演习

  • User.vue
  • router/index.js
  • App.vue

User.vue

  1. <template>
  2. <div>
  3. <h1>User</h1>
  4. <p>uid={{ uid }}, {{ nationality }}</p>
  5. <p>$route.params.uid={{ $route.params.uid }}</p>
  6. <p>$route.params.uid={{ $route.params.nationality }}</p>
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. name: "User",
  12. props: ['uid', 'nationality']
  13. };
  14. </script>

router/index.js

  1. import User from '@/components/User'
  2. ...
  3. {
  4. path: '/',
  5. name: 'Home',
  6. component: Home
  7. },
  8. {
  9. path: '/user/:uid/:nationality',
  10. name: 'User',
  11. component: User,
  12. props: true
  13. },
  14. ...

App.vue

  1. <template>
  2. <div id="app">
  3. <router-link to="/">Home</router-link>
  4. <router-link to="/user/1/usa">User1</router-link>
  5. <router-link to="/user/2/china">User2</router-link>
  6. <router-link to="/user/3/korea">User3</router-link>
  7. <hr>
  8. <router-view></router-view>
  9. </div>
  10. </template>

课程文件

https://gitee.com/komavideo/LearnVueJS2

小马视频频道

http://komavideo.com