vue-routername.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <title>给路由定义名字</title>
  7. <meta name="description" content="">
  8. <meta name="keywords" content="">
  9. <link href="" rel="stylesheet">
  10. </head>
  11. <body>
  12. <div id="app">
  13. <h1>Named Views</h1>
  14. <ul>
  15. <li>
  16. <router-link to="/">/</router-link>
  17. </li>
  18. <li>
  19. <router-link to="/other">/other</router-link>
  20. </li>
  21. </ul>
  22. <router-view></router-view>
  23. <router-view name="a"></router-view>
  24. <router-view name="b"></router-view>
  25. </div>
  26. <script type="text/javascript" src='js/vue.min.js'></script>
  27. <script type="text/javascript" src='js/vue-router.js'></script>
  28. <script type="text/javascript">
  29. const Foo = { template: '<div>11111</div>' }
  30. const Bar = { template: '<div>22222</div>' }
  31. const Baz = { template: '<div>33333</div>' }
  32. const router = new VueRouter({
  33. routes: [
  34. { path: '/',
  35. components: {
  36. default: Foo,
  37. a: Bar,
  38. b: Baz
  39. }
  40. },
  41. {
  42. path: '/other',
  43. components: {
  44. default: Baz,
  45. a: Bar,
  46. b: Foo
  47. }
  48. },
  49. {
  50. path:'*',redirect:'/'
  51. }
  52. ]
  53. })
  54. new Vue({
  55. router,
  56. el: '#app'
  57. })
  58. </script>
  59. </body>
  60. </html>