下面我就为大家分享一篇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('text'+(index+1))">
{{num.t}}
</li>
</ul>
<p class="box">
<component :is='currentView' keep-alive></component>
</p>
</p>
<script src="vue.js"></script>
<script>
const text1 = Vue.component('text1', {template: `<p><h1>Text111111111111</h1></p>`});
const text2 = Vue.component('text2', {template: `<p><h1>Text222222222222</h1></p>`});
const text3 = Vue.component('text3', {template: `<p><h1>Text333333333333</h1></p>`});
const text4 = Vue.component('text4', {template: `<p><h1>Text444444444444</h1></p>`});
const text5 = Vue.component('text5', {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 根据环境传递参数方法来打包不同域名
本文档主要讲述的是Android使用ViewFlipper做页面切换;Android系统自带有一个多页面管理的控件:ViewFlipper.它可以简单实现子页面的切换,它只需使用addView方法添加几个View,每个View对应的是一个页面,即可完成对于多页面的管理。希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看
0
立即学习“前端免费学习笔记(深入)”;
Vue 将后台传过来的带html字段的字符串转换为 HTML
以上就是vue实现tab切换外加样式切换方法的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号