Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My method in vue looks like this :

(我在vue中的方法如下所示:)

methods: { 
    setDate: async function () {
        console.log(this.modal)
    }
}

I want to change it to an arrow function.

(我想将其更改为箭头功能。)

I tried like this :

(我这样尝试过:)

methods: { 
    setDate: async () => {
        console.log(this.modal)
    }
}

There exist error like this :

(存在这样的错误:)

Cannot read property 'modal' of undefined

How can I solve this problem?

(我怎么解决这个问题?)

  ask by positive thinking translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
362 views
Welcome To Ask or Share your Answers For Others

1 Answer

use function directly like

(直接使用功能就像)

methods: { 
    async setDate() {
        console.log(this.modal)
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...