<!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{ 200px; height: 200px; overflow: hidden; background: #ccc; } .container>div{ 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:["按钮一","按钮二","按钮三"], contents:[ "内容一", "内容二", "内容三" ], activeIndex:0 }, methods:{ handleToggle(index){ this.activeIndex = index; } } }) </script>