Assign value from successful promise resolve to external variable

前端 未结 5 1660
陌清茗
陌清茗 2020-12-23 19:23

I have a pretty silly problem. Consider the following:

vm.feed = getFeed().then(function(data) {return data;});

getFeed() retu

5条回答
  •  忘掉有多难
    2020-12-23 20:10

    This could be updated to ES6 with arrow functions and look like:

    getFeed().then(data => vm.feed = data);
    

    If you wish to use the async function, you could also do like that:

    async function myFunction(){
        vm.feed = await getFeed();
        // do whatever you need with vm.feed below
     }
    

提交回复
热议问题