Skip to content
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

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

Open
lzxb opened this issue Aug 21, 2022 · 11 comments

Comments

@lzxb
Copy link

lzxb commented Aug 21, 2022

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

@jaeming
Copy link

jaeming commented Aug 25, 2022

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

@lzxb
Copy link
Author

lzxb commented Aug 26, 2022

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

Our internal component library is developed based on it

@wlhyl
Copy link

wlhyl commented Sep 4, 2022

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

@rootux
Copy link

rootux commented Sep 6, 2022

Love it - will give it a try

@thalysmg
Copy link

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.

@lzxb
Copy link
Author

lzxb commented Sep 27, 2022

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
Copy link
Author

lzxb commented Sep 27, 2022

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

@lzxb
Copy link
Author

lzxb commented Sep 27, 2022

<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
Copy link
Author

lzxb commented Sep 27, 2022

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

@thalysmg
Copy link

thalysmg commented Oct 4, 2022

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...

@lzxb
Copy link
Author

lzxb commented Oct 4, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants