class属性的computed写法示例

<!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://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        .red{
            color:red
        }
        .font{
            font-size: 30px;
        }
    </style>
</head>
<body>
    <div id="app">
        <span :class="classObject">hello world</span>
    </div>
    <script>
       var v= new Vue({
            el:"#app",
            data:{
                isTrue:true
            },
            computed:{
                classObject:function(){
                    return  ['font',{'red':this.isTrue}]
                }
            }
        });
    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/kukai/p/12853224.html