Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 26, 2018 22:09
Show Gist options
  • Save parzibyte/db2a8b8bf7d1938eae4bdd4a9d818ae8 to your computer and use it in GitHub Desktop.
Save parzibyte/db2a8b8bf7d1938eae4bdd4a9d818ae8 to your computer and use it in GitHub Desktop.
methods: {
baseUrl() {
return `https://${this.idiomaSeleccionado.abreviacion}.wikipedia.org/w/api.php?action=query&list=search&srprop=snippet&format=json&origin=*&utf8=&srsearch=`
},
buscar: _.debounce(function() {
let url = `${this.baseUrl()}${encodeURIComponent(this.busqueda)}`;
let esto = this;
fetch(url)
.then(function(respuesta) {
return respuesta.text().then(function(texto) {
return esto.quitarHTML(texto);
});
})
.then(function(jsonValido) {
let respuesta = JSON.parse(jsonValido),
resultados = respuesta.query.search;
esto.resultadosBusqueda = resultados;
});
}, 500),
quitarHTML(html) {
return html.replace(/<\/?[^>]+>/gi, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment