Skip to content

Commit

Permalink
docs: add export example
Browse files Browse the repository at this point in the history
  • Loading branch information
hunyan-io committed May 10, 2023
1 parent 0bf448e commit f66d6b3
Showing 1 changed file with 52 additions and 6 deletions.
58 changes: 52 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Nest SFCs within your SFC.

## Usage
## Install

Install package:

Expand All @@ -34,9 +34,9 @@ export default {
};
```

Add volar plugin for IDE support
Add volar plugin for IDE support:

```json
```jsonc
// tsconfig.app.json
{
"vueCompilerOptions": {
Expand All @@ -45,14 +45,20 @@ Add volar plugin for IDE support
}
```

Use inside SFC
## Usage

### Defining components

Nested components are defined with the `<component>` block. The block's content is treated as if it's a seperate SFC.

```html
<template>
<MyCoolComponent> Hello World! </MyCoolComponent>
<MyHeader>
Hello World!
</MyHeader>
</template>

<component name="MyCoolComponent" lang="vue">
<component name="MyHeader" lang="vue">
<template>
<h1>
<slot />
Expand All @@ -61,6 +67,46 @@ Use inside SFC
</component>
```

### Exporting

You can export nested components with the `export` attribute.

```html
<!-- Button.vue -->
<template>
<button>
<slot />
</button>
</template>

<component name="RoundedButton" lang="vue" export>
<template>
<button>
<slot />
</button>
</template>
<style scoped>
button {
border-radius: 20px;
}
</style>
</component>
```

Import them from other files as named exports.

```html
<!-- App.vue -->
<script setup>
import { RoundedButton } from "./components/Button.vue";
</script>
<template>
<RoundedButton>
Click me
</RoundedButton>
</template>
```

## License

Made with 💛
Expand Down

0 comments on commit f66d6b3

Please sign in to comment.