vue實現tab切換外加樣式切換方法,vuetab

來源:互聯網
上載者:User

vue實現tab切換外加樣式切換方法,vuetab

執行個體如下所示:

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style>  * {   margin: 0;   padding: 0;   list-style: none  }  #app {   width: 504px;   height: 300px;   margin: 100px auto;   border: 1px solid #000;  }  ul {   overflow: hidden;  }  li {   width: 100px;   height: 50px;   float: left;   text-align: center;   line-height: 50px;   border-bottom: 1px solid #000;   border-right: 1px solid #000;  }  li:nth-child(5) {   border-right: none;  }  .cur {   height: 51px;   background: blue;   border-bottom: none;  } </style></head><body><div id="app"> <ul>  <li v-for="(num,index) in nums" :class="{cur:iscur==index}" @click="iscur = index,tab('text'+(index+1))">   {{num.t}}  </li> </ul> <div class="box">  <component :is='currentView' keep-alive></component> </div></div><script src="vue.js"></script><script> const text1 = Vue.component('text1', {template: `<div><h1>Text111111111111</h1></div>`}); const text2 = Vue.component('text2', {template: `<div><h1>Text222222222222</h1></div>`}); const text3 = Vue.component('text3', {template: `<div><h1>Text333333333333</h1></div>`}); const text4 = Vue.component('text4', {template: `<div><h1>Text444444444444</h1></div>`}); const text5 = Vue.component('text5', {template: `<div><h1>Text555555555555</h1></div>`}); var vm = new Vue({  el: "#app",  data: {   currentView: text1,   nums: [{t: "text1"}, {t: "text2"}, {t: "text3"}, {t: "text4"}, {t: "text5"}],   iscur: 0  },  methods: {   tab(tabText){    this.currentView = tabText;   }  } })</script></body></html>

以上這篇vue實現tab切換外加樣式切換方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.