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
Table of contents 1. Introduction 2. Environmenta...
Switching files is a common operation in Linux. W...
Problem Description As we all know, the SQL to so...
To achieve the background color flashing effect, j...
This article describes the MySQL data types and f...
1. Development environment vue+vant 2. Computer s...
1: Differences in speed and loading methods The di...
CenOS6.7 installs MySQL8.0.22 (recommended collec...
I have been making websites for a long time, but I...
1. Basic syntax structure of HTML submit and bott...
There are two installation methods for MySQL: msi...
Using the <img> element with the default sr...
Recommended Docker learning materials: https://ww...
drop table Drop directly deletes table informatio...
Table of contents 01 Introduction to YAML files Y...