登录  /  注册
首页 > web前端 > js教程 > 正文

vue实现tab切换外加样式切换方法

亚连
发布: 2018-05-29 17:58:21
原创
3459人浏览过

下面我就为大家分享一篇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中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号