javascript - Ask about the applicable scenarios of vue.js methods and computed! !
ringa_lee
ringa_lee 2017-06-24 09:43:59
0
4
734

I’ve been a little confused lately. I don’t know when to use which of the two? ? Request for advice

ringa_lee
ringa_lee

ringa_lee

reply all(4)
洪涛

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!