How to use async? for hook functions in vue

  async created () {
    await setTimeout(()=>{
      console.log(1)
    },5000);
  },
  async mounted () {
    console.log(2)
  }

will you use async await, for created in vue or will you output 2 first instead of waiting for 1 to finish?

Mar.29,2021

can achieve this goal in disguise

  async created () {
    this.create_promise = new Promise(resolve=>this.create_promise_resolve=resolve);
    setTimeout(()=>{
        console.log(1);
        this.create_promise_resolve();
    },1000)
  },
  async mounted () {
    await this.create_promise;
    console.log(2)
  }

you have to understand that all subfunctions are only executed at a specified time, and the framework does not care about the results of their execution, so this approach does not meet your needs.

it is recommended that you implement it according to your needs.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a9d6-345f5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a9d6-345f5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?