Take a moment to have a look at the the Altogether now example from Chapter 6, Components. As you can see, we hardcode the stories
array inside the data
object of Vue
instance.
The stories
array hardcoded:
new Vue({ data: { stories: [ { plot: 'My horse is amazing.', writer: 'Mr. Weebl', }, { plot: 'Narwhals invented Shish Kebab.', writer: 'Mr. Weebl', }, ... ] } })
This time, we want to fetch the existing stories from the server.
To do so, we'll perform a HTTP GET
request using jQuery at first. Later on this chapter, we will migrate to vue-resource
(https://github.com/vuejs/vue-resource) to see the differences between the two of them.
To make the AJAX call we are going to use $.get()
, a jQuery function that loads data from the server using a HTTP...