0

Why my code doesn't display the result coming from my API in ExpressJs?

It successfully prints the details in my console but doesn't display on my page.

What could be the reason why this is not working?

This is my console. pic

    <template>
  <div>
    <h1>{{result.First_Name}}</h1>
    <h1>{{result.First_Name}}</h1>
  </div>
</template>

<script>
export default {
  data() {
    return {
      Memb_ID: this.$route.params.Memb_ID,
      result: {}
    };
  },
  created() {
    this.$http
      .get("http://localhost:9000/api/user/" + this.Memb_ID)
      .then(function(data) {
        console.log(data);
        this.result = data.body;
      });
  }
};
</script>

EDIT: I added the screenshot of my console.

Vin
  • 169
  • 2
  • 16
  • What **exactly** does your console show? A screenshot would be good – Phil Jul 08 '19 at 01:04
  • @Phil Hi, I've added the screenshot. Thanks – Vin Jul 08 '19 at 01:10
  • 1
    Oh, never mind. I just realised you aren't using an arrow function so your `this` reference is incorrect. It's an easy fix – Phil Jul 08 '19 at 01:11
  • @Phil how could I fix it? – Vin Jul 08 '19 at 01:13
  • I added a duplicate link for you but it's as simple as changing `.then(function(data) { ... })` to `.then(data => { ... })` – Phil Jul 08 '19 at 01:14
  • @Phil no, still it doesn't display the data – Vin Jul 08 '19 at 01:17
  • 1
    Ok, looking closer, the _data_ in your response is an array so you'd need `{{ result[0].First_Name }}` or something like that. I've added another link that should help – Phil Jul 08 '19 at 01:19

0 Answers0