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: