Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

vue.js - 如何在VueJS中实现箭头功能?(How can I implement arrow function in VueJS?)

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

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

1 Reply

0 votes
by (71.8m points)

use function directly like

(直接使用功能就像)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...