Since I was not sure why this happened, I conducted two tests on jsFiddle:
Sample A:
sample B
Here you notice that in Example B, the execution order is:
- First, data properties are added.
- The created hook is called.
- The calculated property calculates the counter value.
In Example A, step 3 never occurs.
In vue2.1.0 you will get a warning:
Vue warn : an existing instance property of "hasTrigger" will be overwritten by the computed property of the same name.
Further verification in the documents, I found that this warning was suppressed in vue 2.2.2, so you did not receive it, but along with this I found this interesting article:
Requisites and calculated properties are now defined in the prototype of the component, and not as self properties for each instance. This avoids many calls to Object.defineProperty and improves component initialization performance. This will only affect you if you rely on hasOwnProperty checks on details and computed properties, which should be extremely rare, but we document it here to be explicit regarding the changes.
A source
var fancyConstructor = function () { this.value = 5 } var instance = new fancyConstructor() fancyConstructor.prototype.value = 5000 fancyConstructor.prototype.someOtherValue = 5000 console.log(instance.value) console.log(instance.someOtherValue)
you can also delve into each component to find that the truly computed properties are set to counter .

The above snippet illustrates what happens if a property with the same name is present on both the object and the prototype.
Amresh venugopal
source share