Web

实战—实现点击列表item效果切换

2020-07-08  本文已影响0人  瑟闻风倾
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Document</title>
    <script type="text/javascript" src="../first/vue1026.js"></script>
    <style>
        .active{
           background-color: aquamarine; 
        }
    </style>
</head>
<body>
    <div id="app">
        <ul>
            <li v-for="(index,item) in books" :key="item" :class="{active: currentIndex===index}" @click="bookClick(index)">{{item}}</li>
        </ul>
    </div>
</body>
<script type="text/javascript">
    var vm = new Vue({
        el:"#app",
        data:{
            books:['红楼梦','西游记','水浒传','三国演义'],
            currentIndex:0,//记录点击状态
            isClick:true
        },
        methods:{
            bookClick(index){
                this.currentIndex = index
            }
        }
    });
</script>
</html>

上一篇 下一篇

猜你喜欢

热点阅读