<div id="app"> {{method1}} </div> <script> var vue=new Vue({ el:"#app", data:{ a:'1', b:'2', c:'3' }, computed:{ method1:function () { return this.a + this.b + this.c } } }) </script>
以上就是具體的實現代碼,計算屬性要在computed里面聲明方法,方法就相當於一個json數據,方法名相當與鍵,執行邏輯的結果相當於值。通過插值{{方法名}}可以得到方法的執行結果。
