Files
ClassContent/历届学生/fontendseven/每天课程/2021-12-13/tabs.html
2024-09-27 02:06:13 +08:00

99 lines
2.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
.tabs_title {
display: flex;
}
.tabs_title li {
margin-right: 15px;
}
.tabs_title .active {
color: red;
}
.tabs_content li {
display: none;
}
.tabs_content .active {
display: inline-block !important;
}
</style>
</head>
<body>
<div class="app">
<ul class="tabs_title">
<li :class=" index == currentIndex ? 'active' : '' "
v-for="item,index in tabs"
@click="change(index)"
:key="index">
{{ item.text }}
</li>
</ul>
<ul class="tabs_content">
<li :class=" index == currentIndex ? 'active' : '' "
v-for="item,index in tabs"
:key="index">
<p v-for="v,i in item.content" :key="i">{{ v.text }}</p>
</li>
</ul>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
var vm = new Vue({
el: '.app',
data: {
currentIndex: 0,
tabs: [
{
id: 1,
text: '军事',
content: [
{ text: '军事的内容1' },
{ text: '军事的内容2' },
{ text: '军事的内容3' },
]
},
{
id: 2,
text: '社会',
content: [
{ text: '社会的内容1' },
{ text: '社会的内容2' },
{ text: '社会的内容3' },
]
},
{
id: 3,
text: '体育',
content: [
{ text: '体育的内容1' },
{ text: '体育的内容2' },
{ text: '体育的内容3' },
]
}
]
},
methods: {
change(i) {
this.currentIndex = i
}
}
})
</script>
</html>