title: How to make axios synchronous
body: <p>I'm using axios to check if an alias has not already been used by another in the database.</p>
  
  <p><strong>Problem</strong>:
  The ajax call doesn't wait for the server response to execute the remaining code.</p>
  
  <p>The code looks like :</p>
  
  <pre><code>export default {
      data () {
          return {
              id: null,
              alias: null,
              valid: true,
          }
      },
  
      methods: {
          // triggered by the save button
          save () {
              this.valid = true;
              console.log('before checking');
  
              this.checkUniqueness();
              // other validations here
  
              if (this.valid) {
                  console.log('3. checked valid, can save now');
                  // save now
              }
          },
  
          checkUniqueness () {
              axios.get('/api/unique/alias', {
                  params: {
                      id: this.id,
                      alias: this.alias,
                  }
              })
                  .then((response) =&gt; {
                      console.log('2. server response:' + response.data.unique)
                      this.valid = response.data.unique;
                  });
          },
  
      },
  }
  </code></pre>
  
  <p>The console shows the following result:</p>
  
  <pre><code>1. before checking
  3. checked valid, can save now
  2. server response:false
  </code></pre>
  
  <p>I cannot move the code of the <code>save()</code> method into <code>.then</code> because I do other validations on the input data such as alpha-numeric characters, minimum of characters...</p>
  
  <p>I was able to delay the 3rd part (<code>if (this.valid) {</code>) using set <code>setTimeout</code> but it's not the best solution. what if the server takes more or less than the defined waiting time..</p>
  
  <p><strong>Question</strong> Is there a way to make this call sequential (1, 2, 3) instead of (1, 3, 2)?</p>