<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue tab切换</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<style>
ul{
width: 100%;
height:30px;
}
li{
list-style-type:none;
float: left;
margin-left: 20px;
cursor: pointer;
}
</style>
<body>
<div id="app">
<ul>
<li v-for="(item,index) in tabs" @click="tab(index)">{{item}}</li>
</ul>
<div class="tabCon">
<div v-for='(itemCon,index) in tabContents' v-show="index == num">{{itemCon}}</div>
</div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: '#app',
data: {
tabs: ["标题1", "标题2","标题3"],
tabContents: ["内容111111111", "内容22222222","内容333333"],
num: 0
},
methods: {
tab(index) {
this.num = index;
console.log(this.num)
}
}
});
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>vue tab切换</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<style>
ul{
width: 100%;
height:30px;
}
li{
list-style-type:none;
float: left;
margin-left: 20px;
cursor: pointer;
}
</style>
<body>
<div id="app">
<ul>
<li v-for="(item,index) in tabs" @click="tab(index)">{{item}}</li>
</ul>
<div class="tabCon">
<div v-for='(itemCon,index) in tabContents' v-show="index == num">{{itemCon}}</div>
</div>
</div>
vue 实现数据双向绑定 我们不需要管dom 怎么实现 只需要关注视图层
<script type="text/javascript">
var vm = new Vue({
el: '#app',
data: {
tabs: ["标题1", "标题2","标题3"],
tabContents: ["内容111111111", "内容22222222","内容333333"],
num: 0
},
methods: {
tab(index) {
this.num = index;
console.log(this.num)
}
}
});
</script>
</body>
</html>