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!
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
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
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!
methods is generally used to define ordinary functions, computed is used if you need to do some calculations when your data changes
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
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