vue-class-component icon indicating copy to clipboard operation
vue-class-component copied to clipboard

I have implemented the class API based on setup, which is friendly to TS types and supports vue2 and vue3

Open lzxb opened this issue 3 years ago • 11 comments

vue-class-component has been widely used in our projects. vue-class-setup hopes to get official support and further promote the best practices of Vue class. @ktsn

See: https://github.com/fmfe/vue-class-setup

image

image

lzxb avatar Aug 21 '22 09:08 lzxb

This looks very promising. I'll be sure to check it out. Thanks!

jaeming avatar Aug 25 '22 15:08 jaeming

This looks very promising. I'll be sure to check it out. Thanks!

Our internal component library is developed based on it

lzxb avatar Aug 26 '22 02:08 lzxb

vue-class-setup正是所需要的。nice!

wlhyl avatar Sep 04 '22 11:09 wlhyl

Love it - will give it a try

rootux avatar Sep 06 '22 17:09 rootux

One doubt: "Use class style to write setup and support vue2 and vue3". Does it mean that it's purpose is only to write setup, or can we write components just the same way we do in vue-class-component? I didn't get it right.

thalysmg avatar Sep 27 '22 14:09 thalysmg

One doubt: "Use class style to write setup and support vue2 and vue3". Does it mean that it's purpose is only to write setup, or can we write components just the same way we do in vue-class-component? I didn't get it right.

It is not a class component, but it can use classes to write setup, which can be better supported by TS.

lzxb avatar Sep 27 '22 15:09 lzxb

I have used it on a large scale in our company, involving as many as 100+ projects, and it can run well.

lzxb avatar Sep 27 '22 15:09 lzxb


<script lang="ts">
import { defineComponent } from 'vue';
import { Setup, Context } from 'vue-class-setup';

// Setup and Context must work together
@Setup
class App extends Context {
    private _value = 0;
    public get text() {
        return String(this._value);
    }
    public set text(text: string) {
        this._value = Number(text);
    }
    public onClick() {
        this._value++;
    }
}
export default defineComponent({
    // Inject setup
    ...App.inject(),
});
</script>
<template>
    <div>
        <p>{{ text }}</p>
        <button @click="onClick()"></button>
    </div>
</template>

This is the simplest example, and it is somewhat similar to a class component.

lzxb avatar Sep 27 '22 15:09 lzxb

It cannot export a class like a class component. It needs to be put into defineComponent for use, so that type inference can be obtained

lzxb avatar Sep 27 '22 15:09 lzxb

It cannot export a class like a class component. It needs to be put into defineComponent for use, so that type inference can be obtained

Perfect! Thank you for clarifying my doubt.

Is there any forecast to get official support? I'm afraid of starting to use it, and it just gets abandoned like they did with vue-class-component.

I'm starting to migrate my class components to normal ts components because of that...

thalysmg avatar Oct 04 '22 13:10 thalysmg

It cannot export a class like a class component. It needs to be put into defineComponent for use, so that type inference can be obtained

Perfect! Thank you for clarifying my doubt.

Is there any forecast to get official support? I'm afraid of starting to use it, and it just gets abandoned like they did with vue-class-component.

I'm starting to migrate my class components to normal ts components because of that...

There is no official reply at present, but I will maintain it.

lzxb avatar Oct 04 '22 14:10 lzxb