vue-hover的实现

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        ul{
            margin:100px ;
        }
        li{
            width: 50px;
            height: 50px;
            border: 1px solid;
            float: left;
            text-align: center;
            line-height: 50px ;
        }
        .act{
            background: red;
        }
    </style>
</head>
<body>
<ul id="app">
    <li  @click="fun(x)" v-for="x in num" :class="index===x?'act':''">{{x}}</li>
</ul>
</body>
<script src="vue.js"></script>
<script>
    const app=new Vue({
        el:"#app",
        data:{
            num:10,
            index:1,
        },
        methods:{
            fun(x){
               this.index=x
            }
        }



    })



</script>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_42413689/article/details/81707950