<!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>Vue实现选项卡</title>
<style>
.active{
background-color: rgb(142, 240, 240);
}
.button{
border:none;
border-radius: 10px;
margin-right: 20px;
}
</style>
</head>
<body>
<div id="app">
<button @click="current=0" class="button" :class="current==0?'active':''">选项卡1</button>
<button @click="current=1" class="button" :class="current==1?'active':''">选项卡2</button>
<button @click="current=2" class="button" :class="current==2?'active':''">选项卡3</button>
<hr>
判断是否符合,符合即创建,不符合销毁
<div v-show="current==0">
<p>111</p>
<p>222</p>
</div>
<div v-show="current==1">
<p>333</p>
<p>444</p>
</div>
<div v-show="current==2">
<p>555</p>
<p>666</p>
</div>
</div>
<script src="./vue.global.js"></script>
<script>
Vue.createApp({
data(){
return{
current:666
}
}
}).mount('#app') //挂载到id
</script>
</body>
</html>
Vue实现选项卡
于 2022-12-14 20:40:59 首次发布