Skip to content

Instantly share code, notes, and snippets.

@parzibyte

parzibyte/methods.js

Created Mar 26, 2018
Embed
What would you like to do?
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