title: VueJS - Can't access assigned this.property declared within mounted() in mounted()
body: <p>I'm doing a project where I'm fetching an api data from my backend laravel with axios get and using its property to concatenate a channel within the mounted section of my component.</p>
  
  <p>I'm fetching api/user through axios get which contains</p>
  
  <pre><code>{
    "id": 1,
    "name": "admin",
    "email": "admin@company.com",
    "email_verified_at": null,
    "created_at": "2019-08-17 10:06:14",
    "updated_at": "2019-11-27 02:03:30",
    "phone_number": "+12345678911",
    "phone_number_verified": 0,
    "company_id": 1,
    "verification_code": "",
    "signature": "",
    "signature_image": null,
  }
  </code></pre>
  
  <p>Here's how I'm getting the user data from my laravel backend through axios:</p>
  
  <pre><code>mounted() {
    this.$http
      .get('/api/user')
      .then(response =&gt; ( this.user = response.data ))
      .catch(error =&gt; console.log(error))
  },
  </code></pre>
  
  <p>Which is then declared as an empty array in my data() section as such:</p>
  
  <pre><code>data() {
    return {
      user: [],
    };
  },
  </code></pre>
  
  <p>I can access the properties for example, id, in my template through {{ user.id }} and when I try to access it within the mounted() section, it gives me an object but when I try console.log(this.user.id) within the mounted, it throws undefined instead. The reason I need to access this.user.id within the mounted section is because I'm using it to concatenate the channel I'm using through Laravel Echo given as such:</p>
  
  <pre><code>mounted() {
    this.$http
      .get('/api/user')
      .then(response =&gt; ( this.user = response.data ))
      .catch(error =&gt; console.log(error))
  
    this.$echo
      .channel(`new-notification.${this.user.id}`)
      .listen('NewNotification', (data) =&gt; {
      // eslint-disable-next-line no-alert
        this.notifications.unshift(data);
      });
  },
  </code></pre>
  
  <p>I'm fairly new to Vue and I don't know what I'm doing wrong in this. It would be of great help if someone can point out what I'm doing wrong or if there's a better method of doing it.</p>