Skip to content

JavaScript:AsyncFunction

How to call an async function

  async requestProject() {
    try {
      const groups = await this.$api2.getAdminGroups();
      this.groupItems = groups.map(i => i.slug);

      const group_slug = this.$route.params.group;
      const project_slug = this.$route.params.project;
      const projects = await this.$api2.getAdminProjectsPgroupPproject(
          group_slug, project_slug
      );
      this.updateProject(projects)
    } catch (error) {
      this.toastRequestFailure(error);
      this.moveToBack();
    }
  }

호출 방법:

    (async () => {
      await this.requestProject();
    })();

See also