vue.js 一次性同时更新多个数据变量

2019-01-14 16:33:13 阅读:4 编辑
<!doctype HTML>
<HTML lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Document</title>
    <style>
        p.active {color: red;}
        p.title {font-weight: 700;}
        [v-cloak]{display: none !important;}

    </style>
</head>
<body>
<div id="App" v-cloak>
    <button v-on:click="modify_msg ()">modify</button>
    <p v-bind:class="{active:is_active}" class="title">
        {{msg}}
    </p>
    <p>{{msg2}}</p>
</div>

</body>
<script src="/vendor/images/vue.js"></script>
<script>
    new Vue ({
        el: '#App',
        data: {
            msg: "hello",
            msg2: "hello2",
            is_active: false,
        },
       watch:{msg:function () {console.log ("msg watch");
           }
       },
        methods:{modify_msg:function (){
                //this.msg = "ccc";
                //this.msg2 = "cccd";
                Object.assign (this,{msg:'ccc'});
                Object.assign (this,{msg:'ccc','msg2':'seses'});
            }
        }
    });
</script>
</HTML>