This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples): add jsx example (#6870)
Co-authored-by: Pooya Parsa <[email protected]>
- Loading branch information
Showing
8 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
template: Example | ||
--- | ||
|
||
# JSX / TSX | ||
|
||
This example shows how to use [jsx syntax](https://vuejs.org/guide/extras/render-function.html#jsx-tsx) with typescript in Nuxt pages and components. | ||
|
||
::ReadMore{link="https://vuejs.org/guide/extras/render-function.html#jsx-tsx"} | ||
:: | ||
|
||
::sandbox{repo="nuxt/framework" branch="main" dir="examples/advanced/jsx" file="nuxt.config.ts"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script lang="tsx" setup> | ||
// Component could be a simple function with JSX syntax | ||
const Welcome = () => <span>Welcome </span> | ||
// Or using defineComponent setup that returns render function with JSX syntax | ||
const Nuxt3 = defineComponent(() => { | ||
return () => <span>nuxt3</span> | ||
}) | ||
// We can combine components with JSX syntax too | ||
const InlineComponent = () => ( | ||
<div> | ||
<Welcome /> | ||
<span>to </span> | ||
<Nuxt3 /> | ||
</div> | ||
) | ||
</script> | ||
|
||
<template> | ||
<NuxtExampleLayout example="advanced/jsx"> | ||
<InlineComponent /> | ||
<!-- Defined in components/jsx-component.ts --> | ||
<MyComponent message="This is an external JSX component" /> | ||
</NuxtExampleLayout> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default defineComponent({ | ||
props: { | ||
message: String | ||
}, | ||
render: (props) => { | ||
return ( | ||
<div> | ||
{ props.message } | ||
</div> | ||
) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineNuxtConfig } from 'nuxt' | ||
|
||
export default defineNuxtConfig({ | ||
modules: [ | ||
'@nuxt/ui' | ||
] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "example-jsx", | ||
"private": true, | ||
"scripts": { | ||
"build": "nuxi build", | ||
"dev": "nuxi dev", | ||
"start": "nuxi preview" | ||
}, | ||
"devDependencies": { | ||
"@nuxt/ui": "^0.2.0", | ||
"nuxt": "npm:nuxt3@latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./.nuxt/tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters