Skip to content

Instantly share code, notes, and snippets.

@tegain
Last active February 10, 2021 19:59
Show Gist options
  • Save tegain/0d178c7982d863dfcec988cd8d228128 to your computer and use it in GitHub Desktop.
Save tegain/0d178c7982d863dfcec988cd8d228128 to your computer and use it in GitHub Desktop.
Comprendre les composants
/**
* Ce composant Vue...
*/
export default Vue.extend({
name: "AppButton",
props: {
icon: {
type: String,
default: null
},
radius: {
type: String,
default: "medium",
validator(value) {
return ["medium", "small", "large"].includes(value)
}
}
}
});
/**
* est équivalent à écrire ceci
*/
class AppButton {
constructor (
private icon: string | null = null,
private radius: string = "medium"
) {
if (!["medium", "small", "large"].includes(value)) {
throw new Error("Invalid prop type")
}
}
private sayHello() {
console.log('coucou')
console.log(this.icon)
}
}
<AppButton icon="activity" radius="small">Mon texte</AppButton>
// Est équivalent à :
new AppButton("activity", "small")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment