1
/* eslint-disable eol-last */
<template>

<div id="app">
    <ul>
      <li v-for="item in items">  /*  this list is not displaying */
        {{ item.id }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'app',
  data: {
    items: []
  },
  created () {
    this.fetchData()
  },
  methods: {
    fetchData () {
      this.$http.get('http://url/api/users')
        .then(result => {
          this.items = result.data
        })
    }
  }
}
</script>

this list is not displaying i am unable to print this in template. Json returns data but could not access in template.please guide me. Where i am making mistake.

1
  • Adding a debugger; before this.items = result.data and inspecting result.data. Its an array as expected? Commented Apr 19, 2017 at 9:12

1 Answer 1

2

The Problem might be that in your Ajax callback you try to assign to THIS.items but THIS has wrong scope. Create a variable before the ajax call E.g let self = this; And in the ajax cb: self.items = response.data;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.