Last active
June 13, 2024 07:25
-
-
Save Kcko/a855affe1381d0eca49f1fabc7672702 to your computer and use it in GitHub Desktop.
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 setup> | |
import { reactive } from 'vue' | |
import LinkList from "./LinkList.vue" | |
const links = reactive([ | |
{ | |
id: 1, | |
name: "AA", | |
bookmarked: false, | |
}, | |
{ | |
id: 2, | |
name: "BB", | |
bookmarked: false, | |
} | |
]) | |
</script> | |
<template> | |
<LinkList :links="links" v-slot="{ link, bookmarkButtonAttrs, bookmarkButtonEvents, bookmarkNow }"> | |
<button | |
v-bind="bookmarkButtonAttrs" | |
@mouseover="bookmarkNow()" | |
v-on="bookmarkButtonEvents" | |
>{{ link.name }}</button> | |
| | |
</LinkList> | |
</template> | |
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
<!-- | |
Url: https://adamwathan.me/renderless-components-in-vuejs/ | |
Jeho pristup je predavani atributu a eventu jako cely objekt, moje je :bookmarkNow a prijde mi to lepsi teda ... ale ukladam. | |
--> | |
<script setup> | |
const props = defineProps({ | |
links: { | |
type: Array, | |
required: true | |
} | |
}) | |
const bookmark = (link) => { | |
link.bookmarked = !link.bookmarked; | |
} | |
</script> | |
<template> | |
<slot | |
v-for="(link, index) in links" | |
:key="link.id" | |
:link="link" | |
:bookmarkNow="() => bookmark(link)" | |
:bookmarkButtonAttrs="{ | |
style: link.bookmarked ? 'font-weight: bold;' : '' | |
}" | |
:bookmarkButtonEvents="{ | |
click: () => bookmark(link) | |
}" | |
/> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment