vue实现TAB切换

<!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>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <style>
        #app>div{
            font-size: 50px;
        }
        .colorChange{
            background-color: red;
        }
    </style>
</head>

<body>
    <div id='app'>
        <span :style="style"  @click="one(index)" v-for="(item,key,index) in obj" :class="indexs == index?'colorChange':''">{{key}}</span>
        <div v-for='(item,key,index) in obj' v-show='index == indexs'>{{item}}</div>
    </div>
</body>
<script>
    const vm = new Vue({
        el: "#app",
        data: {
            obj:{
                'title1' : 'content1', 
                'title2' : 'content2', 
                'title3' : 'content3'
            },
            indexs : 0,
            style:{
                'border':'1px solid red',
                'padding':'5px 14px'
            }
        },
        methods: {
            // 点击事件
            one(index){
                this.indexs = index;
            }
        },
    });
</script>

</html>

 

posted @ 2021-09-14 21:31  从入门到入土  阅读(136)  评论(0编辑  收藏  举报