How to use Vue to write a simple function tab

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    
        .btnAtive{
            background: red;
            color: #fff;
        }
        .container{
            width:200px;
            height: 200px;
            overflow: hidden;
            background: #ccc;
        }

        .container>div{
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
    <div id="app">
        <button v-for="(item,index) in btns"
            :class="activeIndex == index?'btnAtive':''"
            @click="handleToggle(index)"
        >{{item}}</button>
        <div class="container">
            <div v-for="(item,index) in contents" v-show="activeIndex == index">{{item}}</div>
        </div>
    </div>
</body>
</html>
<script src="./vue.js"></script>
<script>
    var vm = new Vue({
        el:"#app",
        Data: { 
            btns: [ "button a", "button two", "button three" ], 
            Contents: [
                 "Content a" ,
                 "Content of" ,
                 "the contents of three" 
            ], 
            activeIndex: 0 
        }, 
        Methods: { 
            handleToggle (index) { 
                the this .activeIndex = index; 
            } 
        } 
    })
 </ Script>

 

Guess you like

Origin www.cnblogs.com/r-mp/p/11224145.html