Created
July 31, 2020 17:17
-
-
Save MartinMalinda/1f41bfc4b208b4a5eae93dbb0c379dd0 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(200); | |
const { value } = event.target; | |
const { results } = yield searchSpecies(value, { signal }); | |
return results; | |
}).keepLatest(); | |
return { searchTask }; | |
}, | |
}); | |
</script> | |
<template> | |
<div> | |
<br /> | |
<div> | |
<input placeholder="Search species..." @input="searchTask.perform" /> | |
<span v-if="searchTask.isRunning">☁️</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