Преглед изворни кода

include computed properties in vm.$log() (close #1251)

Evan You пре 10 година
родитељ
комит
d8d55858be
2 измењених фајлова са 12 додато и 0 уклоњено
  1. 6 0
      src/api/data.js
  2. 6 0
      test/unit/specs/api/data_spec.js

+ 6 - 0
src/api/data.js

@@ -136,5 +136,11 @@ exports.$log = function (path) {
   if (data) {
     data = JSON.parse(JSON.stringify(data))
   }
+  // include computed fields
+  if (!path) {
+    for (var key in this.$options.computed) {
+      data[key] = this[key]
+    }
+  }
   console.log(data)
 }

+ 6 - 0
test/unit/specs/api/data_spec.js

@@ -18,6 +18,11 @@ describe('Data API', function () {
         double: function (v) {
           return v * 2
         }
+      },
+      computed: {
+        d: function () {
+          return this.a + 1
+        }
       }
     })
   })
@@ -150,6 +155,7 @@ describe('Data API', function () {
       console.log = function (val) {
         expect(val.a).toBe(1)
         expect(val.b.c).toBe(2)
+        expect(val.d).toBe(2)
         spy()
       }
       vm.$log()