刚刚接触Vue,先学着做一些简单的效果
点击按钮切换div的颜色

<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
    <style>
        #app div{
            width: 200px;
            height: 200px;
        }
        #one{
            background-color: blue;
        }
        .one{
            background-color: aqua;
        }
    </style>
</head>
<body>
    <div id="app">
        <div v-bind:[attr]='one'> </div>
        <button @click='color'>按钮</button>
    </div>
    <script>
        new Vue({
            el:'#app',
            data:{ 
                attr:'id',
                one:'one'
            },
            methods:{
             color(){
                 if(this.attr=='class'){
                     this.attr='id'
                 }else if(this.attr=='id'){
                    this.attr='class'
                 }
             }
            }
        })
    </script>
</body>
Logo

前往低代码交流专区

更多推荐