Files
ClassContent/历届学生/吴欣阳/每天课程/2021-07-16/vue/tabs.html
2024-09-27 02:06:13 +08:00

93 lines
1.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body,ul,li {
margin: 0;
padding: 0;
}
.tabs {
width: 300px;
margin: 10% auto;
}
.title {
display: flex;
align-items: center;
height: 45px;
justify-content: space-between;
}
.title .active {
color: red;
}
.tabs_content .c_item {
display: none;
}
.tabs_content .active {
display: block !important;
}
</style>
</head>
<body>
<div class="app">
<div class="tabs">
<div class="title">
<div @click="changeTitle(i)" class="tabs_title"
:class="i == currentIndex ? 'active': '' "
v-for="(v,i) in tab">{{ v.title }}</div>
</div>
<div class="tabs_content">
<div class="c_item" :class="i == currentIndex ? 'active' : '' " v-for="(v, i) in tab">
<p v-for="item in v.content">{{ item.content }}</p>
</div>
</div>
</div>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
new Vue({
el: '.app',
data: {
currentIndex: 0,
tab: [
{
title: '社会',
content: [
{ content: '社会的内容1' },
{ content: '社会的内容2' },
{ content: '社会的内容3' },
]
},
{
title: '军事',
content: [
{ content: '军事的内容1' },
{ content: '军事的内容2' },
{ content: '军事的内容3' },
]
},
{
title: '财经',
content: [
{ content: '财经的内容1' },
{ content: '财经的内容2' },
{ content: '财经的内容3' },
]
}
]
},
methods: {
changeTitle(i) {
this.currentIndex = i
console.log(i)
}
}
})
</script>
</html>