vuejs / vuejs/docs

"Usage Restrictions" confuses me

Open
#1,841 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Vue
Stars
3.2k
Forks
5k
Avg merge
14d 17h
Merged PRs (30d)
1

Description

The following is the original text:

Composables should only be called synchronously in <script setup> or the setup() hook. In some cases, you can also call them in lifecycle hooks like onMounted().

These are the contexts where Vue is able to determine the current active component instance. Access to an active component instance is necessary so that:

Lifecycle hooks can be registered to it.

Computed properties and watchers can be linked to it for disposal on component unmount.

TIP

<script setup> is the only place where you can call composables after usage of await. The compiler automatically restores the active instance context after the async operation for you.

I think this information is important, but it's too abbreviated.
It's easy misunderstanding it. Can we add some code examples?
It seems the first sentence and sentence in Tip are contradictory.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the quoted "Usage Restrictions" section and review how its statements about synchronous composable calls, lifecycle hooks, and await in <script setup> relate. Add code examples and clarify the apparent contradiction, then verify that the revised explanation makes the allowed contexts and await behavior unambiguous.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.