I’ve been a little confused lately. I don’t know when to use which of the two? ? Request for advice
PHP中文网2017-06-24 09:45:59
1.computed is used when you want to monitor changes in data. When the monitored data changes, the calculation will be performed immediately and the result will be returned.
2.methods only defines functions. If you want to execute it, you have to execute it manually!
淡淡烟草味2017-06-24 09:45:59
methods is generally used to define ordinary functions, computed is used if you need to do some calculations when your data changes
巴扎黑2017-06-24 09:45:59
Computed Properties-vs-Methods
1. Computed attributes are cached based on attribute dependencies. Computed attributes will only be re-evaluated when their related dependencies change
When the attribute value does not change, the evaluation will immediately return the previous result, while methods need to be re-calculated, so the evaluation of attributes with dependencies needs to be cached Use computed, use methods if not cached
2. Use methods if there are no attribute dependencies
黄舟2017-06-24 09:45:59
computed will monitor changes, evaluation, method, if you want to call, write HTML trigger method, such as inputchange event, and computed can monitor changes for a certain field