This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| created() { | |
| // Making the http request with Fetch API | |
| const API = 'https://restcountries.eu/rest/v2/all'; | |
| fetch(API, {method: 'GET'}) | |
| .then(res => res.json()) | |
| .then((json) => { | |
| // Place results into the state property | |
| this.countries = json; | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <body> | |
| <div id="app"> | |
| <h1>Vue Search</h1> | |
| <br> | |
| <!-- Search field --> | |
| <input | |
| type="text" | |
| placeholder="Search for a Country" | |
| > |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <body> | |
| <!-- Importing --> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script> | |
| </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "countries": [ | |
| { | |
| "country": "Afghanistan", | |
| "states": ["Badakhshan", "Badghis", "Baghlan", "Balkh", "Bamian", "Daykondi", "Farah", "Faryab", "Ghazni", "Ghowr", "Helmand", "Herat", "Jowzjan", "Kabul", "Kandahar", "Kapisa", "Khost", "Konar", "Kondoz", "Laghman", "Lowgar", "Nangarhar", "Nimruz", "Nurestan", "Oruzgan", "Paktia", "Paktika", "Panjshir", "Parvan", "Samangan", "Sar-e Pol", "Takhar", "Vardak", "Zabol"] | |
| }, | |
| { | |
| "country": "Albania", | |
| "states": ["Berat", "Dibres", "Durres", "Elbasan", "Fier", "Gjirokastre", "Korce", "Kukes", "Lezhe", "Shkoder", "Tirane", "Vlore"] | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| created() { | |
| const API_POSTS = 'https://jsonplaceholder.typicode.com/posts'; | |
| fetch(API_POSTS, {method: 'GET'}) | |
| .then(res => res.json()) | |
| .then(json => { | |
| this.posts = json; | |
| /* Set loading to false after the content | |
| is ready to be displayed */ | |
| this.loading = false; | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const vueapp = new Vue({ | |
| el: '#vueapp', | |
| data() { | |
| return { | |
| msg: 'Hello World', | |
| posts: [], | |
| loading: true | |
| }; | |
| }, | |
| // Other part of the code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <section id="vueapp"> | |
| <article | |
| class="post" | |
| v-for="post in posts" | |
| :key="post.id" | |
| v-if="!loading" | |
| > | |
| <h1 class="title">{{ post.title }}</h1> | |
| <p>{{ post.body }}</p> | |
| </article> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <section id="vueapp"> | |
| <article class="post" v-for="post in posts" :key="post.id"> | |
| <h1 class="title">{{ post.title }}</h1> | |
| <p>{{ post.body }}</p> | |
| </article> | |
| </section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| const vueapp = new Vue({ | |
| el: '#vueapp', | |
| data() { | |
| return { | |
| posts: [] | |
| }; | |
| }, | |
| created() { | |
| const API_POSTS = 'https://jsonplaceholder.typicode.com/posts'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>Vue.js</title> | |
| <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> | |
| </head> | |
| <body> | |