This repository was archived by the owner on Apr 6, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
2.guide/3.directory-structure Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ export default defineComponent({
3434```
3535
3636``` ts [pages/index.tsx]
37+ // https://v3.nuxtjs.org/examples/advanced/jsx
3738// https://vuejs.org/guide/extras/render-function.html#jsx-tsx
3839export default defineComponent ({
3940 render () {
Original file line number Diff line number Diff line change 1+ ---
2+ template : Example
3+ ---
4+
5+ # JSX / TSX
6+
7+ 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.
8+
9+ :: ReadMore { link =" https://vuejs.org/guide/extras/render-function.html#jsx-tsx " }
10+ ::
11+
12+ :: sandbox { repo =" nuxt/framework " branch =" main " dir =" examples/advanced/jsx " file =" nuxt.config.ts " }
Original file line number Diff line number Diff line change 1+ <script lang="tsx" setup>
2+ // Component could be a simple function with JSX syntax
3+ const Welcome = () => <span >Welcome </span >
4+
5+ // Or using defineComponent setup that returns render function with JSX syntax
6+ const Nuxt3 = defineComponent (() => {
7+ return () => <span >nuxt3</span >
8+ })
9+
10+ // We can combine components with JSX syntax too
11+ const InlineComponent = () => (
12+ <div >
13+ <Welcome />
14+ <span >to </span >
15+ <Nuxt3 />
16+ </div >
17+ )
18+ </script >
19+
20+ <template >
21+ <NuxtExampleLayout example =" advanced/jsx" >
22+ <InlineComponent />
23+ <!-- Defined in components/jsx-component.ts -->
24+ <MyComponent message =" This is an external JSX component" />
25+ </NuxtExampleLayout >
26+ </template >
Original file line number Diff line number Diff line change 1+ export default defineComponent ( {
2+ props : {
3+ message : String
4+ } ,
5+ render : ( props ) => {
6+ return (
7+ < div >
8+ { props . message }
9+ </ div >
10+ )
11+ }
12+ } )
Original file line number Diff line number Diff line change 1+ import { defineNuxtConfig } from 'nuxt'
2+
3+ export default defineNuxtConfig ( {
4+ modules : [
5+ '@nuxt/ui'
6+ ]
7+ } )
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " example-jsx" ,
3+ "private" : true ,
4+ "scripts" : {
5+ "build" : " nuxi build" ,
6+ "dev" : " nuxi dev" ,
7+ "start" : " nuxi preview"
8+ },
9+ "devDependencies" : {
10+ "@nuxt/ui" : " ^0.2.0" ,
11+ "nuxt" : " npm:nuxt3@latest"
12+ }
13+ }
Original file line number Diff line number Diff line change 1+ {
2+ "extends" : " ./.nuxt/tsconfig.json"
3+ }
Original file line number Diff line number Diff line change @@ -6759,6 +6759,15 @@ __metadata:
67596759 languageName : unknown
67606760 linkType : soft
67616761
6762+ " example-jsx@workspace:examples/advanced/jsx " :
6763+ version : 0.0.0-use.local
6764+ resolution : " example-jsx@workspace:examples/advanced/jsx"
6765+ dependencies :
6766+ " @nuxt/ui " : ^0.2.0
6767+ nuxt : " npm:nuxt3@latest"
6768+ languageName : unknown
6769+ linkType : soft
6770+
67626771" example-layouts@workspace:examples/routing/layouts " :
67636772 version : 0.0.0-use.local
67646773 resolution : " example-layouts@workspace:examples/routing/layouts"
You can’t perform that action at this time.
0 commit comments