vue implements simple click to switch colors

code show as below:

<!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>

To achieve the effect:

Reprinted in vue to achieve simple click to switch colors

Guess you like

Origin www.cnblogs.com/south-wood/p/12741786.html