练习题2_tab标签页.html 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="./js/vue.js"></script>
  8. <style>
  9. .tab-page{
  10. width: 600px;
  11. height: 400px;
  12. border:3px solid #000;
  13. margin: 100px auto;
  14. }
  15. .tab-nav{
  16. height: 60px;
  17. background-color: #333;
  18. }
  19. .tab-nav .tab-item{
  20. float: left;
  21. height: 60px;
  22. width: 120px;
  23. text-align: center;
  24. line-height: 60px;
  25. color: #fff;
  26. }
  27. .tab-nav .tab-item.active{
  28. background-color: #ddd;
  29. color: #000;
  30. }
  31. .tab-content{
  32. padding:20px;
  33. }
  34. /* .tab-content .tab-content-item{
  35. display: none;
  36. }
  37. .tab-content .tab-content-item.active{
  38. display: block;
  39. } */
  40. </style>
  41. </head>
  42. <body>
  43. <div id="app" class="tab-page">
  44. <div class="tab-nav">
  45. <!-- <div v-bind:class="['tab-item',{'active':activeIndex==0}]" @click="changeTab(0)">第一节课</div>
  46. <div :class="['tab-item',{'active':activeIndex==1}]" @click="changeTab(1)">第二节课</div>
  47. <div :class="['tab-item',{'active':activeIndex==2}]" @click="changeTab(2)">第三节课</div> -->
  48. <div v-bind:class="['tab-item',{'active':activeIndex==0}]" @click="activeIndex=0">第一节课</div>
  49. <div :class="['tab-item',{'active':activeIndex==1}]" @click="activeIndex=1">第二节课</div>
  50. <div :class="['tab-item',{'active':activeIndex==2}]" @click="activeIndex=2">第三节课</div>
  51. </div>
  52. <div class="tab-content">
  53. <div class="tab-content-item" v-if="activeIndex==0">第一节课的内容</div>
  54. <div class="tab-content-item" v-else-if="activeIndex==1">第二节课的内容</div>
  55. <div class="tab-content-item" v-else-if="activeIndex==2">第三节课的内容</div>
  56. </div>
  57. </div>
  58. <script>
  59. new Vue({
  60. el:"#app",
  61. data:{
  62. activeIndex:0
  63. },
  64. methods:{
  65. // changeTab(index){
  66. // console.log(index)
  67. // this.activeIndex = index
  68. // }
  69. }
  70. })
  71. </script>
  72. </body>
  73. </html>