Blogger Information
Blog 28
fans 0
comment 0
visits 30057
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
vue路由制作一个选项卡
G
Original
944 people have browsed it

vue路由制作一个选项卡的原理:

通过router-link代替a标签,然后通过锚点来调用router-view来渲染当前页面,并通过每个选项卡的路径和对应的组件来实现路径的指定和模板的创建,最后决定该选项卡最后要给用用户呈现什么样的内容,最后达到不刷新实现选项卡的切换。


  1. <body>
  2. <div class="app">
  3. <!-- vue的路由功能其实相当于a标签,但是是基于锚点来实现的。 -->
  4. <!-- 通过router-link自定义标签来代替a标签 -->
  5. <!-- 4.2将配置的路由地址通过to添加到router-link标签之中 -->
  6. <h2>GGG导航选项卡</h2>
  7. <router-link to="/video">视频教程</router-link>
  8. <router-link to="/page">技术文章</router-link>
  9. <router-link to="/link">友情链接</router-link>
  10. <router-link to="/page2">技术文档</router-link>
  11. <!-- 渲染路由 -->
  12. <router-view></router-view>
  13. </div>
  14. <!-- 1.导入vue -->
  15. <script src="/11月/1112/lib/vue.js"></script>
  16. <!-- 2.导入vue路由 -->
  17. <script src="vue-router-dev/dist/vue-router.js"></script>
  18. <script>
  19. // 3.创建每个选项卡的(路劲和对应的组件)
  20. const video = {
  21. template: "<p>PHP视频</p><br><p>html视频</p>",
  22. };
  23. const page = {
  24. template: "<p>PHP教程</p>",
  25. };
  26. const link = {
  27. template: "<p>PHP中文网</p>",
  28. };
  29. const page2 = {
  30. template: "<p>vue文档</p>",
  31. };
  32. // 4.注册路由
  33. const router = new VueRouter({
  34. // 4.1配置的过程:
  35. routes: [
  36. // path:路由的路径;component:路由对应的组件
  37. { path: "/video", component: video },
  38. { path: "/page", component: page },
  39. { path: "/link", component: link },
  40. { path: "/page2", component: page2 },
  41. ],
  42. });
  43. new Vue({
  44. router,
  45. el: ".app",
  46. });
  47. </script>
  48. </body>

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:用锚点来实现选项卡, 是不是有点意思呢
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post