# Overview
:::warning
This library is no longer actively maintained. It is no longer recommend to use Class-based components in Vue 3. The recommended way to use Vue 3 in large applications is Single-File Components, Composition API, and `<script setup>`. If you still want to use classes, check out the community-maintained project [`vue-facing-decorator`](https://facing-dev.github.io/vue-facing-decorator/#/).
:::
Vue Class Component is a library that lets you make your Vue components in class-style syntax. For example, below is a simple counter component written with Vue Class Component:
```vue
<template>
<div>
<button v-on:click="decrement">-</button>
{{ count }}
<button v-on:click="increment">+</button>
</div>
</template>
<script>
import Vue from 'vue'
import Component from 'vue-class-component'
// Define the component in class-style
@Component
export default class Counter extends Vue {
// Class properties will be component data
count = 0
// Methods will be component methods
increment() {
this.count++
}
decrement() {
this.count--
}
}
</script>
```
As the example shows, you can define component data and methods in the intuitive and standard class syntax by annotating the class with the `@Component` decorator. You can simply replace your component definition with a class-style component as it is equivalent with the ordinary options object style of component definition.
By defining your component in class-style, you not only change the syntax but also can utilize some ECMAScript language features such as class inheritance and decorators. Vue Class Component also provides a [`mixins` helper](guide/extend-and-mixins.md#Mixins) for mixin inheritance, and a [`createDecorator` function](guide/custom-decorators.md) to create your own decorators easily.
You may also want to check out the `@Prop` and `@Watch` decorators provided by [Vue Property Decorator](https://github.com/kaorun343/vue-property-decorator).
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
用于类样式Vue组件的ESTypeScript装饰器。_TypeScript_JavaScript_下载.zip (71个子文件)
vue-class-component-master
yarn.lock 370KB
.eslintrc.js 208B
hooks.js 64B
.github
CONTRIBUTING.md 1KB
ISSUE_TEMPLATE.md 422B
.circleci
config.yml 1KB
src
reflect.ts 1KB
declarations.ts 465B
globals.d.ts 111B
data.ts 1KB
index.ts 789B
util.ts 2KB
component.ts 5KB
LICENSE 1KB
docs
guide
annotate-component-type-in-decorator.md 1KB
hooks-auto-complete.md 1KB
additional-hooks.md 2KB
installation.md 4KB
props-definition.md 1KB
refs-type-extension.md 1019B
custom-decorators.md 2KB
property-type-declaration.md 1KB
class-component.md 3KB
caveats.md 2KB
extend-and-mixins.md 2KB
.vuepress
config.js 1KB
assets
vue-cli-3.png 17KB
vue-cli-1.png 13KB
vue-cli-2.png 22KB
api
README.md 1KB
README.md 2KB
dist
vue-class-component.esm.js 10KB
vue-class-component.global.js 12KB
vue-class-component.esm-browser.prod.js 3KB
vue-class-component.esm.browser.min.js 3KB
vue-class-component.cjs.js 12KB
vue-class-component.min.js 4KB
vue-class-component.esm.browser.js 8KB
vue-class-component.common.js 10KB
vue-class-component.js 11KB
vue-class-component.esm-browser.js 7KB
vue-class-component.global.prod.js 6KB
vue-class-component.esm-bundler.js 11KB
vue-class-component.d.ts 3KB
package.json 2KB
build
dev-test.js 398B
build.js 4KB
release.sh 477B
test
.eslintrc.js 49B
webpack.config.js 434B
test-babel.js 5KB
.babelrc 199B
tsconfig.json 205B
test.ts 9KB
.gitignore 94B
.eslintignore 195B
tsconfig.json 392B
hooks.d.ts 508B
.gitpod.yml 305B
example
webpack.config.js 804B
src
store.ts 273B
main.ts 180B
App.vue 2KB
components
Hello.vue 281B
World.tsx 216B
shims-tsx.d.ts 222B
shims-vue.d.ts 72B
.babelrc 133B
index.html 215B
tsconfig.json 382B
README.md 2KB
共 71 条
- 1
资源评论
快撑死的鱼
- 粉丝: 2w+
- 资源: 9148
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功