Files
ClassContent/历届学生/18课程/class18_2/课程/2021-01-07/tabs.html
2024-09-27 02:06:13 +08:00

114 lines
2.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.tabstitle {
overflow: hidden;
}
.tabstitle li{
float: left;
margin-right: 20px;
list-style: none;
}
.active {
color: red;
}
</style>
</head>
<body>
<div class="app">
<ul class="tabstitle">
<li v-for="item,index in Tabs"
@click="currentIndex = index"
:class="currentIndex == index ? 'active' : '' "
:key="index">
{{item.title}}
</li>
</ul>
<ul class="tabscontent">
<li v-for="item,index in Tabs[currentIndex].content"
:key="index">
{{ item.name }}
</li>
</ul>
<div class="sss" ref="sss">哈哈哈</div>
<div @click="test">点我 {{hello}}</div>
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var vm = new Vue({
el: '.app',
data: {
currentIndex: 0,
Tabs: [
{
title: '社会',
content: [
{ name: '社会1' },
{ name: '社会1' }
]
},
{
title: '军事',
content: [
{ name: '军事1' },
{ name: '军事1' }
]
},
{
title: '财经',
content: [
{ name: '财经1' },
{ name: '财经1' }
]
}
]
},
beforeCreate() {
// console.log(document.querySelector(".sss"));
console.log(this.currentIndex);
},
watch: {
// Tabs(newVal,oldVal) {
// console.log("newVal: ", newVal);
// console.log("oldVal: ", oldVal);
// }
Tabs: {
handler(newVal,oldVal) {
console.log("newVal: ", newVal);
console.log("oldVal: ", oldVal);
},
deep: true
}
},
// 发送ajax请求
created() {
console.log(this.currentIndex);
},
// 一般需要和dom进行交互的操作放在这
mounted() {
console.log(this.$refs.sss);
},
beforeUpdate() {
console.log("beforeUpdate");
},
methods: {
test() {
alert("111")
}
},
computed: {
hello() {
return "qwdwqdwq"
}
}
})
</script>
</html>