Vue中async await的使用及执行顺序

  methods: {
    getAll() {
      return new Promise((resolve, reject) => {
        this.$axios.get(eventApi.getAllUsers).then(response => {
          let a = response.data[0];
          console.log(a);
          resolve(a);
        });
      });
    },
    getlog() {
      return new Promise((resolve, reject) => {
        console.log("111");
        resolve("111");
      });
    },
    getLog2() {
      console.log("222");
    },
    getlog3() {
      setTimeout(() => {
        console.log("333");
      }, 100);
    },
    getlog4() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          console.log("444");
          resolve();
        }, 1000);
      });
    },
    async getAllData() {
      await this.getlog();
      await this.getlog4();
      await this.getAll();
      await this.getlog3();
      await this.getLog2();
    }
Vue中async await的使用及执行顺序_第1张图片
image.png

想要await按照预期来执行,就必须是promise

不理解的请留言!哈哈哈,我会告诉你

你可能感兴趣的:(Vue中async await的使用及执行顺序)