/app.js

Project Structure

The reply from the NYT API looks like this, via Vue devtools:

<script src=”app.js”></script>

<script src=”https://unpkg.com/axios/dist/axios.min.js”></script>

More often than not, when constructing your JavaScript application, you will want to fetch information from a remote resource or have an API. I recently looked into some publicly available APIs and found that there is plenty of cool stuff which can be done with information from such sources.

Const vm = new Vue(
el:’#app’,
data:
outcomes: [
title:”the very first article”, abstract:”lorem ipsum some test dimpsum”,
title:”and then there was the next”, abstract:”lorem ipsum some evaluation dimsum”,
name:”third time’s a charm”, subjective:”lorem ipsum some test dimsum”,
name:”four the last time”, abstract:”lorem ipsum some test dimsum”
]

);

We inform Vue what element to mount , via the el option, and define what information our app would use through the data alternative.

We can make a petition to get a list of top stories in the home segment, once our Vue app is mounted:
Here Is What the Last app will appear like:
<! -- . /index.html -->

<! DOCTYPE html>

First, we'll create a new Vue instance on the element div#app, and mock the answer from the news API Working with some test data:

To use this NYTimes API, you'll need to have an API key. Therefore, if you don't already have one, head over to their signup page and register for an API key for the Top Stories API.
Including axios:

Note: previously, vue-resource was commonly used with Vue jobs, but it's been retired now.
Axios is a promise-based HTTP customer for making Ajax requests, and will work good for all our purposes. It gives a rich and simple API. It's very similar to this fetch API, but without the need to add a polyfill for older browsers, and another subtleties.

<! -- . -- >
Recall: substitute your_api_key with your real API key obtained from the NYT Dev Network area.

<script src="https://unpkg.com/vue"></script>
The article Fetching Data from a Third-party API with Vue.js and Axios appeared on SitePoint.

/app.js

To exhibit this data in our app perspective, we can write this markup inside the #app component:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/css/foundation.min.css">
App.js will comprise all of the logic for our program, along with also the index.html file will include our app's main view.
We'll keep things very simple by restricting ourselves
The v-for directive is used for producing our list of results. We also use double curly braces to show the contents of every one of them.
Optionally, Foundation could be included, to make the most of some pre-made designs and also make our view look somewhat nicer. Include this inside the <mind > label:

Making Ajax Requests and Handling Replies

Fetching Data from the API

To follow along with this tutorial, you'll want a very basic understanding of Vue.js. You can discover a good"getting started" manual for that here. I'll also be using ES6 Syntax, also you can get a refresher on such here.
We'll start off with a few basic markup in index.html:
Note: you can read more on the Vue Template Syntax here.

With Vue.js, you can literally build a program around among these services and begin serving content to users in minutes.

We now have the basic layout

Developing a Simple Vue App

. /index.html

. /app.js

I'll demonstrate how to build a very simple news app that will reveal the top news articles of this day enable users to filter by their group of interest, fetching data from that the New York Times API. You may find the complete code for this tutorial here.

Then include Vue.js and app.js at the bottom of index.html, just before the closing </body> label:

Now we may observe the news feed on the program homepage. Don't Be Concerned about the perspective; we will get to this in just a bit: