I want to make a simple calculator.
Which one is better for watch or computed when I want to calculate multiple calculation results for one value?

The following is a simple method to detect changes in numbers, execute processing, and output the results.

Value:<input type = "number" v-model = "val">
watch: {
  val: function (value) {
    this.val = value;
    // parseInt
    // function to convert string to integer
    var val = parseInt (value);
    this.val = parseInt (value);
    this.add = Math.floor (val + 2);
    this.sub = Math.floor (val-2);
    this.mult = Math.floor (val * 2);
    this.div = Math.floor (val/2);
I want to achieve it with computed

watch made it easy.
But can this be done with computed? I tried and tried various things, but I couldn't.
Please let me know if it is feasible.

If i can't or don't like it, please let us know why.

  • Answer # 1

    I don't know because there is no code

    If you look at the calculated property-vs-monitoring property
    I think it's easy to understand how to change from watch to computed