风华正茂、时光流逝、真爱时光、努力创建辉煌。

【vue】---选项卡-------【案例 】

<!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>
        #content{
            width: 200px;
            height: 200px;
            background: #ccc;
            overflow: hidden;
        }
        #content>div{
            width: 200px;
            height: 200px;
        }
        .active{
            background: red
        }
    </style>
</head>
<body>
    <div id="app">
          <!-- 绑定属性,作用可以动态调整样式 -->
        <button 
             v-for="(item,index) in btns" 
            :class="index == activeIndex?'active':''"
          
            @click="handleToggle(index)"
            >{{item}}</button>
        <div id="content">
                <!-- v-show="activeIndex == index"  值为true的时候显示,false的时候隐藏    -->
            <div v-for="(item,index) in contents" v-show="activeIndex == index">{{item.text}}</div>
        </div>
    </div>
</body>
</html>
<script src="vue.js"></script>
<script>
 var vm = new Vue({
     el:"#app",
     data:{
         activeIndex:0,//这个当做为一个桥梁作用,中间环节
         btns:['按钮一','按钮二','按钮三'],
         contents:[
             {
                 text:"页面一"
             },
             {
                 text:"页面二"
             },
             {
                 text:"页面三"
             }
         ]
     },
     methods: {
        handleToggle(index){
            this.activeIndex = index;
        }
     },
 })
</script>

 

posted @ 2019-08-07 11:52  野马,程序源改造新Bug  阅读(113)  评论(0)    收藏  举报