Last active
July 31, 2020 16:58
-
-
Save MartinMalinda/63008ebb198ae165b26494806aba8555 to your computer and use it in GitHub Desktop.
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> | |
function searchSpecies(term, options) { | |
return ajax( | |
`https://api.gbif.org/v1/species/search?q=${term}&rank=GENUS`, | |
options | |
); | |
} | |
export default defineComponent({ | |
setup() { | |
const searchTask = useTask(function*(signal, event) { | |
yield timeout(700); | |
const { value } = event.target; | |
const { results } = yield searchSpecies(value, { signal }); | |
return results; | |
}).restartable(); | |
return { searchTask }; | |
}, | |
}); | |
</script> | |
<template> | |
<div> | |
<br /> | |
<div> | |
<input placeholder="Search species..." @input="searchTask.perform" /> | |
<span v-if="searchTask.isRunning">Searching...</span> | |
</div> | |
<div v-if="searchTask.lastSuccessful"> | |
<div v-for="specie in searchTask.lastSuccessful.value"> | |
{{ specie }} | |
</div> | |
</div> | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment