Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue 3 with TypeScript and <script setup> #21

Open
linosteenkamp opened this issue Apr 5, 2022 · 1 comment
Open

Vue 3 with TypeScript and <script setup> #21

linosteenkamp opened this issue Apr 5, 2022 · 1 comment

Comments

@linosteenkamp
Copy link

Documentation clarification:

If using Vue 3 with TypeScript and <script setup> this will work for you

<script setup lang="ts">
import { directive as vClickAway } from 'vue3-click-away'

const onClickAway = (event: any) => {
  console.log(event)
}
</script>

<template>
  <div v-click-away="onClickAway"></div>
<template>

note: The v prefix in import { directive as vClickAway } from 'vue3-click-away' is key as per the Vue documentation

In <script setup>, any camelCase variable that starts with the v prefix can be used as a custom directive. In the example above, vFocus can be used in the template as v-focus

@jdriesen
Copy link

Thanks @linosteenkamp.
Very nice and clean example.

Can I "prevent" in one way or another that the event is being fired ?
PS.: using "event.stopPropagation" in the onClickAway() function is not working...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants