Skip to content

add usage that pass setup function to defineComponent #455

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

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/api/global-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ const MyComponent = defineComponent({
})
```

Or a `setup` function, function name will be used as component name

```js
import { defineComponent, ref } from 'vue'

const HelloWorld = defineComponent(function HelloWorld() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: could we change the syntax here to ES6?

Suggested change
const HelloWorld = defineComponent(function HelloWorld() {
const HelloWorld = defineComponent(HelloWorld() => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, it's not a valid js(ts) syntax 😂. function is used to keep the document concise, because if use arrow function, code in document should be like

const HelloWorld = () => {
    ....
}

// since `HelloWorld` is already defined in the scope, use `HelloWorldComponent` instead
const HelloWorldComponent = defineComponent(HelloWorld)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't pay enough attention when was writing the suggestion 🤦🏻 You're right

const count = ref(0)
return { count }
})
```

## defineAsyncComponent

Creates an async component that will be loaded only when it's necessary.
Expand Down