Blogger Information
Blog 21
fans 0
comment 0
visits 14736
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
(1116)使用 vue 路由,写一个选项卡
Yuming
Original
735 people have browsed it

使用 vue 路由,写一个选项卡

  • 选项卡,这个每个网页都会有的一个计数,现在我将通过 react vue js 实现一个门户网站的选项卡,对比着看更有意思
  1. 下面是我通过 vue 实现门户网站的选项卡的部分关键代码
  1. <template>
  2. <div class="home">
  3. <div class="nav">
  4. <div class="logo"><img src="../assets/logo.png" alt="" /></div>
  5. <div class="tabSelect">
  6. <div
  7. :class="currentIndex == 0 ? 'active' : null"
  8. @click="tabChange(0)"
  9. data-index="0"
  10. >
  11. <router-link to="/index">首页</router-link>
  12. </div>
  13. <div
  14. :class="currentIndex == 1 ? 'active' : null"
  15. @click="tabChange(1)"
  16. data-index="1"
  17. >
  18. <router-link to="/pic">画友圈 </router-link>
  19. </div>
  20. <div
  21. :class="currentIndex == 2 ? 'active' : null"
  22. @click="tabChange(2)"
  23. data-index="2"
  24. >
  25. <router-link to="/nearby">附近画友</router-link>
  26. </div>
  27. <div
  28. :class="currentIndex == 3 ? 'active' : null"
  29. @click="tabChange(3)"
  30. data-index="3"
  31. >
  32. <router-link to="/country">各地画廊</router-link>
  33. </div>
  34. <div
  35. :class="currentIndex == 4 ? 'active' : null"
  36. @click="tabChange(4)"
  37. data-index="4"
  38. >
  39. <router-link to="/world">全球展览</router-link>
  40. </div>
  41. <div
  42. :class="currentIndex == 5 ? 'active' : null"
  43. @click="tabChange(5)"
  44. data-index="5"
  45. >
  46. <router-link to="/elec">电子图录</router-link>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. // @ is an alias to /src
  54. export default {
  55. name: "Home",
  56. components: {},
  57. data() {
  58. return {
  59. currentIndex: 0,
  60. };
  61. },
  62. methods: {
  63. tabChange(index) {
  64. this.currentIndex = index;
  65. },
  66. },
  67. };
  68. </script>
  1. 下面是我通过 react 实现门户网站的选项卡的部分关键代码
  1. // header组件
  2. render() {
  3. return (
  4. <div className="contianer">
  5. <img src={logo} alt="" />
  6. <ul>
  7. <li>
  8. <Link to="/home">首页</Link>
  9. </li>
  10. <li>
  11. <Link to="/pic">画友圈</Link>
  12. </li>
  13. <li>
  14. <Link to="/nearby">附近画友</Link>
  15. </li>
  16. <li>
  17. <Link to="/country">各地画廊</Link>
  18. </li>
  19. <li>
  20. <Link to="/world">全球展览</Link>
  21. </li>
  22. <li>
  23. <Link to="/elec">电子图录</Link>
  24. </li>
  25. </ul>
  26. </div>
  27. );
  28. }
  1. // 根组件
  2. render() {
  3. return (
  4. <div className="container">
  5. <BrowserRouter>
  6. <div className="header">
  7. <Headers />
  8. </div>
  9. <div className="content">
  10. <Redirect to="/home" />
  11. <Route path="/home" component={Home}></Route>
  12. <Route path="/pic" component={Pic}></Route>
  13. <Route path="/nearby" component={Nearby}></Route>
  14. <Route path="/country" component={Country}></Route>
  15. <Route path="/world" component={World}></Route>
  16. <Route path="/elec" component={Elec}></Route>
  17. </div>
  18. <div className="footer">
  19. <Footer />
  20. </div>
  21. </BrowserRouter>
  22. </div>
  23. );
  24. }

总结:代码还有很多不合理的地方,和可以优化的地方,目前只是实现这个功能,当前代码够用了

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