使用 class 风格编写 composition api,支持Vue2、Vue3

vue-class-setup

Why?

Using class can help you avoid ref , reactive , computed and withDefaults , and significantly reduce your mental burden and better organize your code. It supports vue2 and vue3 at the same time. After gzip compression, it is only 1KB

function vs class

vue-class-component vs vue-class-setup

We should deprecate vue-class-component , and use class in setup

List vue-class-component vue-class-setup
Vue2 :white_check_mark: :white_check_mark:
Vue3 :x: :white_check_mark:
Method bind this :white_check_mark: :white_check_mark:
Props type check :x: :white_check_mark:
Emit type check :x: :white_check_mark:
Watch type check :x: :white_check_mark:
Multiple class instances :x: :white_check_mark:
Class attribute sets the default value of the prop :x: :white_check_mark:

Install

npm install vue-class-setup
# or
yarn add vue-class-setup

Quick start

<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: 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值