Vue-Promise 비동기 및 동기화 처리

1564 단어 Vue


  export default {
    data() {
      return {
         merchandiseName:'default',
         who:'default'
      }
    },
    methods:{
      changeMerchandiseNameAsync(){
        //    
        this.requestMerchandiseName().then(responseMesssage=>{
         this.merchandiseName=responseMesssage;
        }).catch(error=>{
          alert(error);
        });
        //    requestMerchandiseName     
        this.who='  ';
      },

      async changeMerchandiseNameSync(){
         //    
        const responseMesssage = await this.requestMerchandiseName().catch(error=>{
          alert(error);
        });
        this.merchandiseName=responseMesssage;
        //  requestMerchandiseName            
        this.who='  ';
      },

      requestMerchandiseName(){
        return new Promise((resolver,reject)=>{
          setTimeout(() => {
            //reject('error 500');
            resolver('i am learning');
          }, (3000));
        })
      }
    }
  }



좋은 웹페이지 즐겨찾기