Last active
May 8, 2021 02:41
-
-
Save AlexVipond/4235dce783a3e63bf1d75beed89025be to your computer and use it in GitHub Desktop.
Use Vue's computed getters and setters to simplify APIs that might otherwise be esoteric for other developers
This file contains 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 lang="ts"> | |
import { useNavigable } from 'path/to/useNavigable' | |
export default { | |
setup () { | |
const myImages = [...] | |
const { location, next, previous } = useNavigable(myImages) | |
return { | |
myImages, | |
location, | |
next, | |
previous, | |
} | |
} | |
} | |
</script> | |
<template> | |
<button @click="previous"> | |
← | |
</button> | |
<div> | |
<button | |
v-for="(image, index) in myImages" | |
:key="image.src" | |
@click="() => location = index" | |
> | |
<img :src="image.src" :alt="image.alt" /> | |
</button> | |
</div> | |
<button @click="next"> | |
→ | |
</button> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment