Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Prevent calling composables directly in the event handler #2721

Open
@Haberkamp

Description

Please describe what the rule should do:

This rule enforces that you can't directly call a composable inside an event handler.

Calling a composable inside an event handler directly can cause issues. For example when we call
onMounted inside that composable, we'll get an error because onMounted is called outside the Vue context.

Here's an example

What category should the rule belong to?

[ ] Enforces code style (layout)
[X] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

<template>
 <button @click="useFoo">Click me!</button>
</template>
<script setup>
function useFoo() {
 onMounted() {}

 fetch('/api);
}
</script>

Additional context

To determine wether something is a composable, we check if a function starts with use. This is the standard convention for Vue.

Note: I would help to create a PR for that rule

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /