Remove emits, slots, and attrs concepts in Vue.
- 🤐 No need to define props, emits, slots, and attrs in runtime.
- 🦾 Fully TypeScript support.
- 👾 Non-invasive.
npm i vue-simple-props
- Starts with
on
for event handlers. - Starts with
render
for slots. - Others are props.
import { defineFunctionalComponent, useClassAndStyle } from 'vue-simple-props'
interface Props {
foo: string
onClick: () => void
renderDefault?: () => JSX.Element
}
const Comp = defineFunctionalComponent(
(props: Props) => {
const styles = useClassAndStyle()
return () => <div {...styles}>...</div>
},
{
// other options, e.g. name, inheritAttrs, etc.
},
)
<!-- parent.vue -->
<template>
<Comp foo="bar" @click="handleClick">slot</Comp>
</template>
import {
defineSimpleComponent,
useClassAndStyle,
useProps,
} from 'vue-simple-props'
interface Props {
foo: string
onClick: () => void
renderDefault?: () => JSX.Element
}
export const Comp = defineSimpleComponent<Props>({
setup() {
const props = useProps<Props>()
const styles = useClassAndStyle()
return () => <div {...props}>...</div>
},
})
// vite.config.ts
import vueJsx from '@vitejs/plugin-vue-jsx'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
// ...
vueJsx({
defineComponentName: [
'defineComponent',
'defineFunctionalComponent',
'defineSimpleComponent',
],
}),
],
})
inheritAttrs
isfalse
by default.
MIT License © 2023-PRESENT 三咲智子 Kevin Deng