转换为箭头功能

时间:2019-04-16 12:30:19

标签: javascript asynchronous vue.js google-places-api arrow-functions

此处的代码用于从Google Maps上的某个地方获取评论,并将其显示在Vue应用上。

rViewData: function () {
    var self= this;
    var request = {
    placeId: this.placeId,
    fields: ['review']
    };
    var service = new google.maps.places.PlacesService(document.createElement('div'));

    service.getDetails(request, callback);

    function callback(results, status) {
    if (status == google.maps.places.PlacesServiceStatus.OK) {
        console.log(results.reviews.length)
        console.log(results.reviews)
        for await(let o of results.reviews) {
            const name = o.author_name               
            self.reviews.push(name)
            console.log(name)
            }
        }   
    }

现在,我只是在伪装此代码以使其工作;使用self,显式编写回调。.

如何正确将其写为箭头函数?

p.s沙箱https://codesandbox.io/embed/y0vn3rqz1x

0 个答案:

没有答案