1. Introduction The main functions are as follows:
2. Usevue-property-decorator mainly provides the following decorators
1. @Component If you need to define import {Component,Vue} from 'vue-property-decorator'; import {componentA,componentB} from '@/components'; @Component({ components:{ componentA, componentB, }, directives: { focus: // Definition of instruction inserted: function (el) { el.focus() } } } }) export default class YourCompoent extends Vue{ } 2. Computed, data, methods @Component export default class HelloDecorator extends Vue { count: number = 123 // The class attribute is equivalent to the previous data add(): number { // The class method is the same as the previous method this.count + 1 } // Get the calculated attribute get total(): number { return this.count + 1 } // Set the calculated properties set total(param:number): void { this.count = param } } 3. @propsThe component receives the decorator of the attribute, which is used as follows: import {Component,Vue,Prop} from vue-property-decorator; @Component export default class YourComponent extends Vue { @Prop(String) propA: string; @Prop([String,Number]) propB:string|number; @Prop({ type: String, // type: [String , Number] default: 'default value', // usually a String or Number //If it is an object or array. Default value is returned from a factory function // default: () => { // return ['a','b'] // } required: true, validator: (value) => { return [ 'InProcess', 'Settled' ].indexOf(value) !== -1 } }) propC: string; } 4. @watchIt is actually the listener in Vue, as follows: import { Vue, Component, Watch } from 'vue-property-decorator' @Component export default class YourComponent extends Vue { @Watch('child') onChildChanged(val: string, oldVal: string) {} @Watch('person', { immediate: true, deep: true }) onPersonChanged1(val: Person, oldVal: Person) {} @Watch('person') onPersonChanged2(val: Person, oldVal: Person) {} } 5. @emit The import {Vue, Component, Emit} from 'vue-property-decorator'; @Component({}) export default class Some extends Vue{ mounted(){ this.$on('emit-todo', function(n) { console.log(n) }) this.emitTodo('world'); } @Emit() emitTodo(n: string){ console.log('hello'); } } Conclusion You can see that the syntax of the above This is the end of this article on how to apply You may also be interested in:
|
<<: Use of Linux passwd command
>>: Detailed analysis of MySQL master-slave replication
In daily development tasks, we often use MYSQL...
Preface Recently I encountered a requirement, whi...
1. Introduction I won’t go into details about apo...
In this article, the blogger will take you to lea...
I accidentally discovered a great artificial inte...
Table of contents Preface About webSocket operati...
Due to work reasons, it is often not possible to ...
This article example shares the specific code of ...
I believe that many users who make websites will ...
mysql 8.0.22 winx64 installation and configuratio...
Problem background: When using docker to deploy t...
Table of contents 1. Build the Vue environment 2....
Let's start with a description of the problem...
The best thing you can do for your data and compu...
Effect picture (the border color is too light, pu...