1. 程式人生 > 其它 >vue實現TAB切換

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>