Disclaimer: This article is a blogger sigmarising original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/sigmarising/article/details/90762737
Use vue-class-component and vue-property-decorator in the Vue
When using the TypeScript in V2.X version of Vue, it is recommended to use annotation-based development decorator class.
1. Install related
vue-property-decorator was developed based vue-class-component, so only need to install vue-property-decorator to install.
npm i vue-property-decorator
2. Related
vue-class-component provides (article as of V7.1.0):
methods
It can be directly declared as members of the methods of the class- Calculating attribute may be declared property accessor class
- Initialization
data
can be declared as class properties data
,render
As well as all of Vue lifecycle hooks can be used directly as a member of the class's methods- All other attributes, needs to be placed decorator
vue-property-decorator offer (as of this article V8.1.1):
@Prop
@Model
@Watch
@Inject
、@Provide
@Emit
See more detailed usage:
3. Note that undefined initialization data
vue-class-component is not initialized to make undefined
a data
responsive change, should be used null
to initialize or data
hooks.
Details can refer to: