Closed
Description
A month ago I was working in a concept to use Vue 3.0 / Composition API with Statefull classes, the result of this work is here:
https://codesandbox.io/s/test-vue-class-n0iuf?file=/src/components/HelloWorld.vue
- It works with annotations, I implement 4 annotations @watch @prop @Inject @context
- It have a vanilla JS Class without inheritance of Vue.
- It uses setup method with full state.
- It have getters/setters as computed properties
- It also exposes static properties, static getters and static methods.
- I think that it could be full safe typed (although my example is still missing many type declarations 🙄).
- It is small 🤭
import { Component, Inject, Prop, Context, Watch } from "./vue-class";
@Component()
export default class MyComponent {
static VERSION = "1.2";
@Inject()
name: string = "";
@Prop(String)
msg: string;
@Context()
emit: any;
newItem = "";
items = ["Hello", "World"];
setup() {
// this is a reactive component :)
console.log(this.msg);
}
@Watch("counter")
watchCounter() {
console.log("watch counter.. ");
this.emit("hiFather");
}
get counter() {
return this.items && this.items.length;
}
add() {
this.items.push(this.newItem);
}
static uppercase(s: string) {
return s && s.toUpperCase();
}
static get VERSION_NUMBER() {
return parseFloat(this.VERSION) * 10;
}
}
Metadata
Metadata
Assignees
Labels
No labels