首頁  >  文章  >  web前端  >  vue實作tab切換外加樣式切換方法

vue實作tab切換外加樣式切換方法

亚连
亚连原創
2018-05-29 17:58:213625瀏覽

下面我就為大家分享一篇vue實作tab切換外加樣式切換方法,具有很好的參考價值,希望對大家有幫助。

實例如下:

<!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>
<p id="app">
 <ul>
  <li v-for="(num,index) in nums" :class="{cur:iscur==index}" @click="iscur = index,tab(&#39;text&#39;+(index+1))">
   {{num.t}}
  </li>
 </ul>
 <p class="box">
  <component :is=&#39;currentView&#39; keep-alive></component>
 </p>
</p>
<script src="vue.js"></script>
<script>
 const text1 = Vue.component(&#39;text1&#39;, {template: `<p><h1>Text111111111111</h1></p>`});
 const text2 = Vue.component(&#39;text2&#39;, {template: `<p><h1>Text222222222222</h1></p>`});
 const text3 = Vue.component(&#39;text3&#39;, {template: `<p><h1>Text333333333333</h1></p>`});
 const text4 = Vue.component(&#39;text4&#39;, {template: `<p><h1>Text444444444444</h1></p>`});
 const text5 = Vue.component(&#39;text5&#39;, {template: `<p><h1>Text555555555555</h1></p>`});
 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中Npm run build 根據環境傳遞參數方法來包裝不同域名

##利用js實作前後台傳送Json的範例程式碼

Vue 將後台傳過來的帶html欄位的字串轉換為HTML#

以上是vue實作tab切換外加樣式切換方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn