Skip to content

Commit be297e7

Browse files
authored
feat: jsx support
1 parent 6f9d468 commit be297e7

File tree

18 files changed

+163
-34
lines changed

18 files changed

+163
-34
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"no-console":0,
55
"prefer-const":0,
66
"quotes":[1,"double"],
7+
"no-prototype-builtins":0,
78
"vue/no-parsing-error": ["error", {
89
"invalid-first-character-of-tag-name": false
910
}]

example/vue2/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"build": "vite build"
77
},
88
"dependencies": {
9+
"@vue/composition-api": "^1.4.9",
910
"vue": "^2.6.14",
1011
"vue-template-compiler": "^2.6.14"
1112
},

example/vue2/src/App.vue

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
<div class="container">
33
<div>
44
<Hi />
5-
<p>
6-
Welcome to here 🚀 .
7-
</p>
5+
<Welcome />
86
<!-- -->
97
<!-- -->
108
<!-- -->
@@ -13,11 +11,14 @@
1311
</div>
1412
</div>
1513
</template>
16-
<script>
14+
<script lang="ts">
1715
import Hi from "./Hi.vue"
16+
import Welcome from "./Welcome"
1817
export default {
18+
name: "App",
1919
components: {
2020
Hi,
21+
Welcome,
2122
},
2223
}
2324
</script>
@@ -34,9 +35,6 @@ export default {
3435
justify-content: center
3536
p
3637
font-size: 18px
38+
color: #35495d
3739
cursor: pointer
38-
&:nth-of-type(1)
39-
color: #35495d
40-
&:nth-of-type(2)
41-
color: #fcb80f
4240
</style>

example/vue2/src/Hi.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
<template>
22
<div>
33
<h3>Hi</h3>
4+
<!-- -->
5+
<Render :component="boom" />
46
</div>
57
</template>
8+
<script lang="tsx">
9+
import { defineComponent } from "@vue/composition-api"
10+
import { CreateElement } from "vue"
11+
12+
export default defineComponent({
13+
name: "Hi",
14+
components: {
15+
Render: {
16+
functional: true,
17+
props: {
18+
component: Function,
19+
},
20+
render(h: CreateElement, { props }: any) {
21+
return props.component(h)
22+
},
23+
},
24+
},
25+
setup() {
26+
return {
27+
boom: () => <h4 style="cursor: pointer;">🎉</h4>,
28+
}
29+
},
30+
})
31+
</script>
632
<style lang="sass" scoped>
733
h3
834
font-size: 26px

example/vue2/src/Welcome.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineComponent } from "@vue/composition-api"
2+
3+
export default defineComponent({
4+
name: "Welcome",
5+
setup() {
6+
return () => <p style="color: #fcb80f;cursor: pointer;"> Welcome to here 🚀 .</p>
7+
},
8+
})

example/vue2/src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Vue from "vue"
2+
import VueCompositionAPI from "@vue/composition-api"
23
import App from "./App.vue"
34

5+
Vue.use(VueCompositionAPI)
6+
47
new Vue({
58
render: h => h(App),
69
}).$mount("#app")

example/vue2/src/shim-tsx.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { VNode } from "vue"
2+
import { ComponentRenderProxy } from "@vue/composition-api"
3+
4+
declare global {
5+
namespace JSX {
6+
interface Element extends VNode {}
7+
interface ElementClass extends ComponentRenderProxy {}
8+
interface ElementAttributesProperty {
9+
$props: any // specify the property name to use
10+
}
11+
interface IntrinsicElements {
12+
[elem: string]: any
13+
}
14+
}
15+
}

example/vue2/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"useDefineForClassFields": true,
5+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
6+
"strict": true,
7+
"module": "ESNext",
8+
"moduleResolution": "Node",
9+
"jsx": "preserve"
10+
},
11+
"include": ["src"],
12+
}

example/vue2/vite.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import Inspector from "vite-plugin-vue-inspector"
44

55
export default defineConfig({
66
plugins: [
7-
createVuePlugin(),
7+
createVuePlugin({
8+
jsx: true,
9+
jsxOptions: {
10+
compositionAPI: true,
11+
},
12+
}),
813
Inspector({
914
vue: 2,
1015
}),

example/vue3/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"devDependencies": {
1212
"@vitejs/plugin-vue": "^1.10.2",
13+
"@vitejs/plugin-vue-jsx": "^1.3.8",
1314
"@vue/compiler-sfc": "^3.2.24",
1415
"sass": "^1.49.9",
1516
"typescript": "^4.5.2",

0 commit comments

Comments
 (0)