Home > Web Front-end > JS Tutorial > body text

vue implements tab switching plus style switching method

亚连
Release: 2018-05-29 17:58:21
Original
3677 people have browsed it

Below I will share with you an article on how to implement tab switching and style switching in Vue. It has a good reference value and I hope it will be helpful to everyone.

The example is as follows:

<!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>
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Npm run build in vue packages different domain names according to the environment passing parameter method

Use js to realize front and back transfer Json sample code

Vue converts the string with html field passed from the background into HTML

The above is the detailed content of vue implements tab switching plus style switching method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!