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
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
{ | |
"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
<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
<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
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
<input | |
type="text" | |
placeholder="Search for a Country" | |
v-model="search" | |
> |
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
computed: { | |
countriesResults() { | |
// Filter results | |
return this.countries.filter((country) => { | |
return country.name.toLowerCase() | |
.indexOf(this.search.toLowerCase()) > -1; | |
}); | |
} | |
} |
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
<?php | |
$args = array( | |
"posts_per_page" => 8 | |
); | |
$Eventos = new WP_Query($args); | |
if($Eventos->have_posts()){ | |
while($Eventos->have_posts()){ | |
$Eventos->the_post(); | |
// Obtem a imagem de destaque | |
$img = wp_get_attachment_url(get_post_thumbnail_id(get_the_ID())); |
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
// main.js | |
import Vue from "vue"; | |
/** | |
* numberToUSD: It format numbers into the USD currency format. | |
* @param {number} value | |
* @returns {string} value | |
*/ | |
Vue.filter("numberToUSD", value => { | |
return value ? `$${value.toLocaleString("en-US")}` : "$0.0"; |