search

Home  >  Q&A  >  body text

javascript - Ask about the applicable scenarios of vue.js methods and computed! !

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

ringa_leeringa_lee2769 days ago783

reply all(4)I'll reply

  • PHP中文网

    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!

    reply
    0
  • 淡淡烟草味

    淡淡烟草味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

    reply
    0
  • 巴扎黑

    巴扎黑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

    reply
    0
  • 黄舟

    黄舟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

    reply
    0
  • Cancelreply