-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create functional component in @Component? #120
Comments
We need to declare an additional type for |
I just wondered the benefit of using |
Oh, indeed. @lijialing888 Why do you want to use |
Closing since there would not be benefit to use class style syntax for a function component as @kaorun343 described. |
@ktsn import { Component, Vue } from 'vue-property-decorator'
@Component({
functional: true,
props: {
theme: {
type: String,
default: 'default'
}
}
})
export default class Stylesheets extends Vue {
// A bunch of Vue lifecycle methods here and there...
render () {
return null
}
} The In the utils.ts file, there is the following line: export function createDecorator (factory: (options: ComponentOptions<Vue>, key: string, index: number) => void): VueDecorator { The type is ComponentOptions (that do not have export function createDecorator (factory: (options: ComponentOptions<Vue> | FunctionalComponentOptions<Vue>, key: string, index: number) => void): VueDecorator { Does it make sense to change it to something like that? There is some side effects that this could raise? Or maybe a safer If so, a PR on this matter is welcome? |
@marcosmoura I think adding the additional decorator // will error because typescript will assume the type of $refs is Element[]
this.$refs.upload.active = true
// this will work
const upload = this.$refs.upload as MyComponent
upload.active = true So if it use @Component({
functional: true
} as FunctionalComponentOptions)
export default class Stylesheets extends Vue {} @ktsn In my opinion, adding support for functional based class can enhance the usage of template tag for functional component (especially in validating props value) <template functional>
<rect :width="props.size" :height="props.size">
<slot></slot>
</rect>
</template> import { Prop, FunctionalComponent, Vue } from 'vue-property-decorator'
ensureSize(val: number) {
return val > 10 && Math.sqrt(val) < 300
}
@FunctionalComponent()
export default class Square extends Vue {
@Prop({ default: 50, validator: ensureSize })
size: number
} |
Does anybody solve this problem? I trying to make recursive scoped slots for tree-component and I think that I have to access native render method for injecting |
Any solution for this? |
Just use import Vue from 'vue'
export default Vue.extend({
functional: true,
render(h, ctx) {
// ...
}
}) As it's already pointed out the former of this issue, using class style syntax for functional component does not have benefit since functional component does not have its instance. It won't included in this lib since class style functional component does not follows standard class semantics (not have instance, |
Hi guys,
How to create functional component in @component?
It prompts error in Visual Studio Code:
The text was updated successfully, but these errors were encountered: