Vue calculation Properties

the following is a calculation property written, but if it is not shown in span, console.log can print

.

what went wrong

<span>{{areaUser}}</span>


  computed: {
    // 
    areaUser: function () {
      this.areaOptions.forEach( (element, index) => {
        if (element.id === this.temp.areaId) {
          console.log("")  
          return 11111111
        } 
      })
    }
  }
Apr.11,2021

The

clipboard.png
outer function must return a result.

areaUser: function () {
  let value = "";
  this.areaOptions.forEach( (element, index) => {
    if (element.id === this.temp.areaId) {
      console.log('')  
      value = 1111111; //
      return 11111111
    } 
  });
  return value;//computed
}

calculate the property needs a return value as the result of the calculation. You have return here, but the callback function return of forEach is not the calculation of the attribute return. You need to make the following modifications

areaUser: function () {
    var a;
    //forachsome
    this.areaOptions.some( (element, index) => {
        if (element.id === this.temp.areaId) {
            console.log('')  
            a = 11111111
            return true
        } 
    })
    return a
}

< hr > The return value of

computed is taken as the final result.
because when computed writes only one function, it is converted to a get function.

    computend: {
        foo() {
            return this.dataArray.map(v=>v.id)
        }
    }
Menu