-
Notifications
You must be signed in to change notification settings - Fork 98
Closed
Description
Edit by @yyx990803 : there are currently two JSX transform implementations for Vue 3 with slightly differing syntax (for Vue specific features). We are using this thread to unify the design and land on an official specification of how Vue features should be handled in JSX.
Babel JSX Transform [Github]
- patchFlags
- same as Vue 3 Compiler
- compatible with Vue 2.x
Syntax
Content
functional component
const App = () => <div></div>
with render
const App = {
render() {
return <div>Vue 3.0</div>
}
}
const App = defineComponent(() => {
const count = ref(0);
const inc = () => {
count.value++;
};
return () => (
<div onClick={inc}>
{count.value}
</div>
)
})
Fragment
const App = () => (
<>
<span>I'm</span>
<span>Fragment</span>
</>
)
Attributes/Props
const App = () => <input type="email" />
with a dynamic binding:
const placeholderText = 'email'
const App = () => (
<input
type="email"
placeholder={placeholderText}
/>
)
Directives
It is recommended to use camelCase version of it (
vModel
) in JSX, but you can use kebab-case too (v-model
).
v-show
const App = {
data() {
return { visible: true };
},
render() {
return <input vShow={this.visible} />;
},
};
v-model
- You should use underscore (
_
) instead of dot (.
) for modifiers (vModel_trim={this.test}
)
export default {
data: () => ({
test: 'Hello World',
}),
render() {
return (
<>
<input type="text" vModel_trim={this.test} />
{this.test}
</>
)
},
}
custom directive
const App = {
directives: { custom: customDirective },
setup() {
return () => (
<a
vCustom={{
value: 123,
arg: 'arg',
}}
/>
);
},
}
tangjinzhou, DM2489, jvbianchi, anilsahindev, yamagen0915 and 64 morecosimochellini, xrkffgg, uriannrima, OEvgeny, DNature and 5 morecosimochellini, guAnsunyata, tangjinzhou, xrkffgg, uriannrima and 10 morecosimochellini, marshallswain, guAnsunyata, tangjinzhou, edimitchel and 17 morecosimochellini, matepapp, guAnsunyata, takanorip, DNature and 4 more
Metadata
Metadata
Assignees
Labels
No labels