How can I export promise result?

前端 未结 4 1128
南笙
南笙 2021-01-07 23:12

Sorry if this question is stupid.

This code works correctly. And I just need to export data variable after all promises successfully resolved.

I cannot put t

4条回答
  •  盖世英雄少女心
    2021-01-07 23:42

    You should use promise function

    promise.js

    export  function get_data(){
      var get_data= new Promise(function(resolve, reject) {
         //do your stuff 
          return resolve('success');
        }).catch(function () {
          return reject('err');
        });
      
       });
     //return promise 
      return get_data;
    }
    

    Import

    import * as data from './mypromise'
    
    
    data.get_data().then((reuslt)=>{
    console.log(result)})
    

提交回复
热议问题