Use arrow function in vue computed does not work

前端 未结 4 1120
栀梦
栀梦 2020-11-22 07:44

I am learning Vue and facing a problem while using arrow function in computed property.

My original code works fine (See snippet below).

4条回答
  •  伪装坚强ぢ
    2020-11-22 08:14

    The arrow function lost the Vue component context. For your functions in methods, computed, watch, etc., use the Object functions:

    computed:{
        switchRed() {
            return {red: this.turnRed}
        },
        switchGreen() {
            return {green: this.turnGreen}
        },
        switchBlue() {
            return {blue: this.turnBlue}
        }
    }
    

提交回复
热议问题