vue实现简单的点击切换颜色

代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>

    <style>
        div {
            width: 100px;
            height: 100px;
            background: lightcoral;
        }

        .changeColor {
            background: lightseagreen;
        }
    </style>
</head>

<body>
    <section id="app">
        <div :class="{changeColor}" @click="changeColor =! changeColor"></div>
    </section>
    
    <script>
        new Vue({
            el: '#app',
            data: {
                changeColor: false
            }
        })
    </script>
</body>
</html>

实现效果:

转载于vue实现简单的点击切换颜色

posted @ 2020-04-21 00:39  降蓝  阅读(2251)  评论(0编辑  收藏  举报