Files
ClassContent/历届学生/韩一伟/项目开发/练习项目/作业/2021.08.11/tabs.html
2024-09-27 02:06:13 +08:00

93 lines
2.4 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>
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
.tabs_title {
display: flex;
}
.tabs_title li {
margin-right: 10px;
}
.tabs_title_active {
color: red;
}
</style>
</head>
<body>
<div class="app">
<ul class="tabs_title">
<li :class="index == currentIndex ? 'tabs_title_active' : '' "
@click="changeTitle(index)"
v-for="(item,index) in tabsList">
{{ item.title }}
</li>
</ul>
<div class="tabs_content">
<div class="" v-for="(item,index) in tabsList">
<div v-if="index==currentIndex">
<p v-for="(v,i) in item.content">{{ v.text }}</p>
</div>
</div>
</div>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script>
new Vue({
el: '.app',
data: {
currentIndex:0,
tabsList: [
{
id: 1,
title: '社会',
content: [
{ text: '社会的内容1' },
{ text: '社会的内容2' },
{ text: '社会的内容3' },
]
},
{
id: 1,
title: '军事',
content: [
{ text: '军事的内容1' },
{ text: '军事的内容2' },
{ text: '军事的内容3' },
]
},
{
id: 1,
title: '体育',
content: [
{ text: '体育的内容1' },
{ text: '体育的内容2' },
{ text: '体育的内容3' },
]
},
]
},
methods:{
changeTitle(i){
this.currentIndex = i
}
}
})
</script>
</html>