Skip to content

Commit 336f7ff

Browse files
authored
add tsx / jsx exammple (#522)
closes #517
1 parent f02da0e commit 336f7ff

File tree

13 files changed

+1269
-0
lines changed

13 files changed

+1269
-0
lines changed

examples/tsx/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local

examples/tsx/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# tsx
2+
3+
This is an example for TSX

examples/tsx/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

examples/tsx/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "tsx",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vue-tsc --noEmit && vite build",
8+
"serve": "vite preview"
9+
},
10+
"dependencies": {
11+
"vue": "^3.0.11",
12+
"vue-i18n": "link:../../packages/vue-i18n"
13+
},
14+
"devDependencies": {
15+
"@vitejs/plugin-vue": "^1.2.3",
16+
"@vitejs/plugin-vue-jsx": "^1.1.5",
17+
"@vue/compiler-sfc": "^3.0.11",
18+
"typescript": "^4.1.3",
19+
"vite": "^2.3.5",
20+
"vue-tsc": "^0.0.24"
21+
}
22+
}

examples/tsx/public/favicon.ico

4.19 KB
Binary file not shown.

examples/tsx/src/App.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<script lang="tsx">
2+
import { defineComponent } from 'vue'
3+
import { useI18n } from 'vue-i18n'
4+
import HelloWorld from './components/HelloWorld.vue'
5+
6+
export default defineComponent({
7+
name: 'App',
8+
components: {
9+
HelloWorld
10+
},
11+
setup() {
12+
const { t } = useI18n({
13+
inheritLocale: true,
14+
useScope: 'global'
15+
})
16+
return () => (
17+
<>
18+
<HelloWorld msg="Vue I18n v9 + TSX + Vite" />
19+
<p>{ t('hello') }</p>
20+
</>
21+
)
22+
}
23+
})
24+
</script>
25+
26+
<style>
27+
#app {
28+
font-family: Avenir, Helvetica, Arial, sans-serif;
29+
-webkit-font-smoothing: antialiased;
30+
-moz-osx-font-smoothing: grayscale;
31+
text-align: center;
32+
color: #2c3e50;
33+
margin-top: 60px;
34+
}
35+
</style>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<script lang="tsx">
2+
import { defineComponent } from 'vue'
3+
import { useI18n } from 'vue-i18n'
4+
5+
export default defineComponent({
6+
name: 'HelloWorld',
7+
props: {
8+
msg: {
9+
type: String,
10+
required: true
11+
}
12+
},
13+
setup({ msg }) {
14+
const { t } = useI18n({
15+
useScope: 'global',
16+
inheritLocale: true
17+
})
18+
return () => (
19+
<>
20+
<h1>{msg}</h1>
21+
<p>v-t: <span v-t="hello"></span></p>
22+
<i18n-t keypath="term" tag="label" for="tos">
23+
<a href="https://vue-i18n.intlify.dev" target="_blank">{ t('tos') }</a>
24+
</i18n-t>
25+
</>
26+
)
27+
}
28+
})
29+
</script>
30+
31+
<style scoped>
32+
a {
33+
color: #42b983;
34+
}
35+
36+
label {
37+
margin: 0 0.5em;
38+
font-weight: bold;
39+
}
40+
41+
code {
42+
background-color: #eee;
43+
padding: 2px 4px;
44+
border-radius: 4px;
45+
color: #304455;
46+
}
47+
</style>

examples/tsx/src/main.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createApp } from 'vue'
2+
import { createI18n } from 'vue-i18n'
3+
import App from './App.vue'
4+
5+
const i18n = createI18n({
6+
legacy: false,
7+
locale: 'en',
8+
messages: {
9+
en: {
10+
hello: 'Hello world',
11+
tos: 'vue-i18n-next docs',
12+
term: 'access to {0}'
13+
}
14+
}
15+
})
16+
17+
createApp(App).use(i18n).mount('#app')

examples/tsx/src/shims-vue.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module '*.vue' {
2+
import { DefineComponent } from 'vue'
3+
const component: DefineComponent<{}, {}, any>
4+
export default component
5+
}

examples/tsx/src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

0 commit comments

Comments
 (0)