Skip to content

Instantly share code, notes, and snippets.

View firminochangani's full-sized avatar
🖊️
probably shipping software.

Firmino Changani firminochangani

🖊️
probably shipping software.
View GitHub Profile
const vueapp = new Vue({
el: '#vueapp',
data() {
return {
msg: 'Hello World',
posts: [],
loading: true
};
},
// Other part of the code
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;
})
{
"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"]
},
<body>
<!-- Importing -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script>
</body>
<body>
<div id="app">
<h1>Vue Search</h1>
<br>
<!-- Search field -->
<input
type="text"
placeholder="Search for a Country"
>
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;
})
<input
type="text"
placeholder="Search for a Country"
v-model="search"
>
computed: {
countriesResults() {
// Filter results
return this.countries.filter((country) => {
return country.name.toLowerCase()
.indexOf(this.search.toLowerCase()) > -1;
});
}
}
<?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()));
// 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";